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=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,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 BE8C81F461 for ; Sat, 20 Jul 2019 22:58:41 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 911C11209A3; Sun, 21 Jul 2019 07:58:33 +0900 (JST) Received: from o1678916x28.outbound-mail.sendgrid.net (o1678916x28.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id ED3C5120968 for ; Sun, 21 Jul 2019 07:58:30 +0900 (JST) Received: by filter0145p3las1.sendgrid.net with SMTP id filter0145p3las1-1101-5D339C98-D 2019-07-20 22:58:32.58627374 +0000 UTC m=+1479973.303931478 Received: from herokuapp.com (unknown [54.221.26.144]) by ismtpd0010p1iad1.sendgrid.net (SG) with ESMTP id 61ELpPmxTN2NaK3wjXuq7Q for ; Sat, 20 Jul 2019 22:58:32.567 +0000 (UTC) Date: Sat, 20 Jul 2019 22:58:32 +0000 (UTC) From: lourens@bearmetal.eu Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 69361 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 15631 X-Redmine-Issue-Author: ahorek X-Redmine-Issue-Assignee: ko1 X-Redmine-Sender: methodmissing 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?Fr=2F4MkNsnJ5O85XS4movydqTd1a9M98=2FgJAFvUl026PSnGHlqBMz16h+CP9m7K?= =?us-ascii?Q?18cfAvyuHjbGdouLWO4SD9x8O28K97RNkUbbDI5?= =?us-ascii?Q?CofYt0xD7txCt1FDq2C3Y=2Feo77s1hT8XtVbuvxJ?= =?us-ascii?Q?2mODkq1sLEVHne88rWOsNqNOz34297qbicfeFXr?= =?us-ascii?Q?ii+u4HuVusQ6CIw+=2FIcmrgHtkY4Cpupa2IA=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 93861 Subject: [ruby-core:93861] [Ruby master 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 updated by methodmissing (Lourens Naud=E9). Pavel added a new patch for `get_power2` in https://github.com/ruby/ruby/pu= ll/2292 ---------------------------------------- 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#change-79773 * Author: ahorek (Pavel Rosick=FD) * Status: Open * Priority: Normal * Assignee: ko1 (Koichi Sasada) * 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 shifts that makes it slight= ly 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) st.c.patch (455 Bytes) -- = https://bugs.ruby-lang.org/ Unsubscribe: