Skip to content

Memoize Bundler::LazySpecification#hash to improve performance#5534

Closed
technicalpickles wants to merge 1 commit intoruby:masterfrom
technicalpickles:memoize-lazy-specification-hash
Closed

Memoize Bundler::LazySpecification#hash to improve performance#5534
technicalpickles wants to merge 1 commit intoruby:masterfrom
technicalpickles:memoize-lazy-specification-hash

Conversation

@technicalpickles
Copy link
Copy Markdown
Contributor

What was the end-user or developer problem that led to this PR?

In local testing, we found require 'bundler/setup' took 1.8 seconds to load.
I started profiling and looking at flamegraphs for this code, and found
a surprising amount of time in this method.

What is your fix for the problem, implemented in this PR?

Memoizing this specific method reduced time by 0.7 to 1.1 seconds, a 38%
improvement.

Make sure the following tasks are checked

cc @ngan who I paired with on this

In local testing, we found `require 'bundler/setup'` took 1.8 seconds to load.
I started profiling and looking at flamegraphs for this code, and found
a surprising amoutn of time in this method.

Memoizing this specific method reduced time by 0.7 to 1.1 seconds, a 38%
improvement.
@welcome
Copy link
Copy Markdown

welcome bot commented May 13, 2022

Thanks for opening a pull request and helping make RubyGems and Bundler better! Someone from the RubyGems team will take a look at your pull request shortly and leave any feedback. Please make sure that your pull request has tests for any changes or added functionality.

We use GitHub Actions to test and make sure your change works functionally and uses acceptable conventions, you can review the current progress of GitHub Actions in the PR status window below.

If you have any questions or concerns that you wish to ask, feel free to leave a comment in this PR or join our #rubygems or #bundler channel on Slack.

For more information about contributing to the RubyGems project feel free to review our CONTRIBUTING guide

@technicalpickles
Copy link
Copy Markdown
Contributor Author

technicalpickles commented May 13, 2022

I'm attaching the stackprof data as JSON, which can be viewed with speedscope

bundler-test.txt
(is JSON despite name)

And here's the scaffold I used to run it:

require 'benchmark'
require 'stackprof'

result = Benchmark.measure  do
  StackProf.run(mode: :wall, raw: true, out: 'bundler-test.dump', ignore_gc: true) do
    require 'bundler/setup'
  end
end

puts result

@technicalpickles
Copy link
Copy Markdown
Contributor Author

Looks like @ngan beat me too it 😅 This is a subset of #5534

@deivid-rodriguez
Copy link
Copy Markdown
Contributor

Yes! And also I think #5533 should make this unnecessary, can you verify?

@technicalpickles
Copy link
Copy Markdown
Contributor Author

Confirmed that #5533 would address this case 🚀

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants