From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id 838E520248 for ; Fri, 1 Mar 2019 13:48:39 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 74FEA114E9C; Fri, 1 Mar 2019 22:48:34 +0900 (JST) Received: from o1678948x4.outbound-mail.sendgrid.net (o1678948x4.outbound-mail.sendgrid.net [167.89.48.4]) by neon.ruby-lang.org (Postfix) with ESMTPS id 2EE3C1209D0 for ; Fri, 1 Mar 2019 22:48:30 +0900 (JST) Received: by filter0113p3las1.sendgrid.net with SMTP id filter0113p3las1-2513-5C79382C-34 2019-03-01 13:48:28.954458842 +0000 UTC m=+50249.804555371 Received: from herokuapp.com (unknown [54.196.21.121]) by ismtpd0036p1iad1.sendgrid.net (SG) with ESMTP id CE28zxjPSZKbNOuhRHP03g for ; Fri, 01 Mar 2019 13:48:28.065 +0000 (UTC) Date: Fri, 01 Mar 2019 13:48:28 +0000 (UTC) From: pdahorek@seznam.cz Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 67101 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 15631 X-Redmine-Issue-Author: ahorek X-Redmine-Sender: ahorek X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: =?us-ascii?Q?FEBmdr4t2oPyVtJ=2FHwsoNw3OX6yEJVN29QfUTo2MyNPDgCD8HWoc0GckDIuCK8?= =?us-ascii?Q?2dEhKl51Lj+6xgGb8ADJKG1JbmTIgZ3Jsyq76M7?= =?us-ascii?Q?RT677nuw32P2WErTnsMGU0zUdBt7gz+7ctnO+e+?= =?us-ascii?Q?AYpGUC=2F8rwU7mPrJcmbkFXwZ7ox2nR4rajusYaF?= =?us-ascii?Q?XqBqc4BoA5SbiaYrOpvmqVuHbsklgKB8taA=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 91651 Subject: [ruby-core:91651] [Ruby trunk Feature#15631] Let round_capa for ID table not allocate excess capacity for power of 2 ints >= 4 X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #15631 has been reported by ahorek (Pavel Rosick=FD). ---------------------------------------- Feature #15631: Let round_capa for ID table not allocate excess capacity fo= r power of 2 ints >=3D 4 https://bugs.ruby-lang.org/issues/15631 * Author: ahorek (Pavel Rosick=FD) * Status: Open * Priority: Normal * Assignee: = * Target version: = ---------------------------------------- right now round_capa value is rounded up to the next power of 2 ``` round_capa(4) -> returns 8 round_capa(8) -> returns 16 round_capa(16) -> returns 32 round_capa(5) -> returns 8 round_capa(9) -> returns 16 round_capa(17) -> returns 32 etc. ``` it seems wasteful to allocate the extra items capacity, so this PR changes = that to ``` round_capa(4) -> returns 4 round_capa(8) -> returns 8 round_capa(16) -> returns 16 round_capa(5) -> returns 8 round_capa(9) -> returns 16 round_capa(17) -> returns 32 etc. ``` the main purpose is to reduce memory usage especially during boot my patch also uses BUILTIN_CLZ macro instead of hash shifts that makes it s= lightly faster here's a benchmark ```ruby require 'benchmark/ips' Benchmark.ips do |x| x.config(time: 20, warmup: 3) x.report('struct', "Struct.new(*('a'..'z').map { |x| x.to_sym })") end ``` ``` trunk Warming up -------------------------------------- struct 527.000 i/100ms Calculating ------------------------------------- struct 5.461k (=B1 5.5%) i/s - 109.089k in 20.040253s methodmising - POW2_P (github) Warming up -------------------------------------- struct 544.000 i/100ms Calculating ------------------------------------- struct 5.570k (=B1 4.1%) i/s - 111.520k in 20.057245s ahorek - BUILTIN_CLZ (id_table.c.patch) Warming up -------------------------------------- struct 571.000 i/100ms Calculating ------------------------------------- struct 5.812k (=B1 3.6%) i/s - 116.484k in 20.070607s ``` discussion https://github.com/ruby/ruby/pull/2083 ---Files-------------------------------- id_table.c.patch (534 Bytes) -- = https://bugs.ruby-lang.org/ Unsubscribe: