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.7 required=3.0 tests=AWL,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 91CFA1F461 for ; Thu, 11 Jul 2019 07:34:24 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 78E70120AE5; Thu, 11 Jul 2019 16:34:18 +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 E0548120ADE for ; Thu, 11 Jul 2019 16:34:15 +0900 (JST) Received: by filter0081p3mdw1.sendgrid.net with SMTP id filter0081p3mdw1-21722-5D26E67A-A 2019-07-11 07:34:18.164593606 +0000 UTC m=+655656.546164677 Received: from herokuapp.com (unknown [54.80.150.68]) by ismtpd0022p1iad2.sendgrid.net (SG) with ESMTP id YL8csOTESUyCPOncfbAQZw for ; Thu, 11 Jul 2019 07:34:18.068 +0000 (UTC) Date: Thu, 11 Jul 2019 07:34:18 +0000 (UTC) From: ko1@atdot.net Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 69168 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 15631 X-Redmine-Issue-Author: ahorek X-Redmine-Issue-Assignee: ko1 X-Redmine-Sender: ko1 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?fVTMYOBjtdvXNcWwrscBhLsHItUXVK5L4mtnq0mdcRcEpF1jDoefghynDIv0Yv?= =?us-ascii?Q?+e880uyTQImblk6teT=2F1hc8ZEglLI=2FybZPLG5df?= =?us-ascii?Q?sKfVh1GlcL33xL8eG8jFoGUufrkc2qHJuK4GSt1?= =?us-ascii?Q?325ezQrYmSPcNqmFwwxUehSZg3knp+AjEoTFMps?= =?us-ascii?Q?7HcoF3upTuy0F?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 93673 Subject: [ruby-core:93673] [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 ko1 (Koichi Sasada). Assignee set to ko1 (Koichi Sasada) funny_falcon, do you have any opinion? if no opinion, we'll discuss it one month later and will commit it. in fact, I can't check algorithm, so we can try it. ahorek: could you give me more performance measurements? * you should not call `map` in iteration (you should prepare IDs before) * now you only measures 26 fields. could you measure other numbers, 1 to 50= , for example. Thanks, Koichi ---------------------------------------- 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-79284 * 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) -- = https://bugs.ruby-lang.org/ Unsubscribe: