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.