Skip to content

Memory allocations reported on wrong line for blocks in Ruby 2.6.x #87

Description

@jturkel

The following test case reports the allocation of method arguments on different lines for Ruby MRI 2.5/2.7 vs. Ruby MRI 2.6:

require 'bundler/inline'

gemfile do
  source 'https://rubygems.org'
  gem 'memory_profiler', '0.9.14'
end

puts "Ruby: #{RUBY_VERSION}"

def do_something
  yield
end

def do_something_else(options)
  yield
end

report = MemoryProfiler.report do
  100_000.times do
    do_something do
      do_something_else({foo: 1, bar: 2, baz: 3}) do
        # no-op
      end
    end
  end
end

report.pretty_print(retained_strings: 0, allocated_strings: 0)

Running this in Ruby 2.5 and 2.7 reports 100,000 allocations on the do_something_else({foo: 1, bar: 2, baz: 3}) line as expected. Ruby 2.6 incorrectly reports the allocations on the do_something line.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions