Improve performance of Bundler::SpecSet#for by using hash lookup of handled deps#5537
Conversation
7d3f4a8 to
7578bcd
Compare
|
This looks great to me, I run it against the So an extra 4% speed up over current master branch! |
I had a chance to test this against https://github.com/technicalpickles/big-gemfile I cracked open a flamegraph using both the branches, and I'm seeing |
|
I'm not seeing the same results with your sample repository 😮. I get the results that I would expect, namely, this PR improves performance by a lot, but once applied, #5534 and #5536 no longer have any effect. |
Bundler::SpecSet#for by using hash lookup of handled deps
…andled deps
I was looking at (yet another) flamegraph in speedscope, and used the
'left hand heavy' and was shocked to realize that 0.5s of the 1.7s
is spent in DepProxy#name. This method _only_ delegates the name to an
underlying spec, so it's not complex at all.
It seems to be of how often this line ends up calling it:
next if handled.any?{|d| d.name == dep.name && (match_current_platform || d.__platform == dep.__platform) } || dep.name == "bundler"
The `handled` array is built up as dependencies are handled, so this get
slower as more dependencies are installed.
This change changes how `handled` is track. Instead of just an array, I've
tried using a Hash, with the key being a dep's name, and the value being
a list of deps with that name. This means it's constant time to find
the dependencies with the same name.
I saw a drop from 1.7s to 1.0s against master, and from 0.95s to 0.24s
when used with ruby#5533
7578bcd to
844dac3
Compare
|
Let's do this! |
…p-of-handled-deps Improve performance of `Bundler::SpecSet#for` by using hash lookup of handled deps (cherry picked from commit 4b1b2b7)
What was the end-user or developer problem that led to this PR?
Looking for improvements to runtime speed of
require 'bundler/setup'What is your fix for the problem, implemented in this PR?
I was looking at (yet another) flamegraph in speedscope, and used the
'left hand heavy' and was shocked to realize that 0.5s of the 1.7s
is spent in DepProxy#name. This method only delegates the name to an
underlying spec, so it's not complex at all.
It seems to be of how often this line ends up calling it:
The
handledarray is built up as dependencies are handled, so this getslower as more dependencies are installed.
This change changes how
handledis track. Instead of just an array, I'vetried using a Hash, with the key being a dep's name, and the value being
a list of deps with that name. This means it's constant time to find
the dependencies with the same name.
I saw a drop from 1.7s to 1.0s against master, and from 0.95s to 0.24s
when used with #5533
Make sure the following tasks are checked