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-Status: No, score=-2.9 required=3.0 tests=AWL,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY 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 254641F5AE for ; Wed, 15 Jul 2020 14:31:12 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 051D01209AB; Wed, 15 Jul 2020 23:30:42 +0900 (JST) Received: from xtrwkhkc.outbound-mail.sendgrid.net (xtrwkhkc.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id 30EEE1209A7 for ; Wed, 15 Jul 2020 23:30:37 +0900 (JST) Received: by filterdrecv-p3iad2-5b55dcd864-htmgx with SMTP id filterdrecv-p3iad2-5b55dcd864-htmgx-19-5F0F1322-12F 2020-07-15 14:30:58.84821736 +0000 UTC m=+1632102.822650699 Received: from herokuapp.com (unknown) by geopod-ismtpd-1-3 (SG) with ESMTP id 0gkiVjCyREenbF66MTPBeg for ; Wed, 15 Jul 2020 14:30:58.765 +0000 (UTC) Date: Wed, 15 Jul 2020 14:30:58 +0000 (UTC) From: eregontp@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 74966 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Bug X-Redmine-Issue-Id: 17031 X-Redmine-Issue-Author: marcandre X-Redmine-Sender: Eregon 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?KippOI8ZHtTweq7XfQzW93937kJ4QNWwSBuHnaMEcr3rAtOO1hScMKlp0b7pEZ?= =?us-ascii?Q?CQzO47naHPILFKDg9sq8JdMR5ctAoFeBcsOj8ho?= =?us-ascii?Q?0gvEnnSIQMMHS3D=2FTvV3+MlTifu8UWUKreLg7VB?= =?us-ascii?Q?CaziXNLkXmYDrgvxQy++ArXJpS+ATGyU5dXoHsT?= =?us-ascii?Q?1Rhi7URGSt4hV07dpnKauu9lm=2FIKx0LD2PHS2WC?= =?us-ascii?Q?JskAkjKXCakruuvCs=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 99176 Subject: [ruby-core:99176] [Ruby master Bug#17031] `Kernel#caller_locations(m, n)` should be optimized 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="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #17031 has been updated by Eregon (Benoit Daloze). Could you post the results of running that on your computer? Then it's easier to see your point without needing to reproduce. ---------------------------------------- Bug #17031: `Kernel#caller_locations(m, n)` should be optimized https://bugs.ruby-lang.org/issues/17031#change-86555 * Author: marcandre (Marc-Andre Lafortune) * Status: Open * Priority: Normal * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN ---------------------------------------- `Kernel#caller_locations(1, 1)` currently appears to needlessly allocate memory for the whole backtrace. It allocates ~20kB for a 800-deep stacktrace, vs 1.6 kB for a shallow backtrace. It is also much slower for long stacktraces: about 7x slower for a 800-deep backtrace than for a shallow one. Test used: ```ruby def do_something location = caller_locations(1, 1).first end def test(depth, trigger) do_something if depth == trigger test(depth - 1, trigger) unless depth == 0 end require 'benchmark/ips' Benchmark.ips do |x| x.report (:short_backtrace ) {test(800,800)} x.report (:long_backtrace ) {test(800, 0)} x.report (:no_caller_locations) {test(800, -1)} end require 'memory_profiler' MemoryProfiler.report { test(800,800) }.pretty_print(scale_bytes: true, detailed_report: false) MemoryProfiler.report { test(800, 0) }.pretty_print(scale_bytes: true, detailed_report: false) ``` Found when checking memory usage on RuboCop. -- https://bugs.ruby-lang.org/