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=-4.1 required=3.0 tests=AWL,BAYES_00, 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 EB3621F461 for ; Sat, 20 Jul 2019 02:00:05 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id D15B312097D; Sat, 20 Jul 2019 10:59:59 +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 E6ED7120A45 for ; Sat, 20 Jul 2019 10:59:57 +0900 (JST) Received: by filter0085p3las1.sendgrid.net with SMTP id filter0085p3las1-23712-5D3275A0-6 2019-07-20 02:00:00.282014953 +0000 UTC m=+1404701.509049310 Received: from herokuapp.com (unknown [52.87.190.212]) by ismtpd0005p1iad2.sendgrid.net (SG) with ESMTP id 06i7gsZ-S_eE_Sv5V8i84Q for ; Sat, 20 Jul 2019 02:00:00.111 +0000 (UTC) Date: Sat, 20 Jul 2019 02:00:00 +0000 (UTC) From: nobu@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 69356 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 15631 X-Redmine-Issue-Author: ahorek X-Redmine-Issue-Assignee: ko1 X-Redmine-Sender: nobu 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?q8Dly+pU2+3ektTtZVXgZtbJPXwqo7p86jCsvYTW4BxDIiuGDiqyxTtfqkinaE?= =?us-ascii?Q?B7FrE86y5+kpINVJHP4fesM7MC1lnuo03rnzimo?= =?us-ascii?Q?TccQxj0nd2gt8h3zIwc9ya36zK142yrZ2vafqqo?= =?us-ascii?Q?GTr7wFpwKe5WNu9EuXcBqLVmLSqY5Boa3oOAFf7?= =?us-ascii?Q?IvLM=2FyHDdYXWAt38i=2FJX5tQF3K=2FzvyK0ZgQ=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 93856 Subject: [ruby-core:93856] [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 nobu (Nobuyoshi Nakada). It should use `SIZEOF_ST_INDEX_T` and `nlz_intptr`. ---------------------------------------- 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-79755 * 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: