New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve memory usage in Bundler::Settings, and thus improve boot time #6884
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…ng another hash. `String#start_with?` is faster than regex that is bound to the start of a string.
… can use bang methods to avoid allocating new copies
… saves allocating 2 arrays
The individual keys are also new, so we can use ! methods on each individual one as well.
…, which is not used
Use .prepend to avoid allocating a new string.
Nice! A boon for the massively-environmented users everywhere 😂 |
I think I got over-ambitious with this PR, and now I'm getting tons of failures that aren't super obvious where to begin (ie |
segiddins
reviewed
Aug 17, 2023
martinemde
reviewed
Aug 17, 2023
martinemde
reviewed
Aug 17, 2023
@martinemde pushed up those changes! |
segiddins
approved these changes
Aug 19, 2023
Hei, I didn't fin time to chime in here, but THIS IS SO AWESOME! Thank you so much! |
technicalpickles
added a commit
to technicalpickles/rubygems
that referenced
this pull request
Aug 29, 2023
I previously identified and improved this method over in rubygems#6884 but while reviewing another memory_profiler profile, I realized another gain we can eek out. This method keeps comes up in part because `configs` is allocating a new Hash every time. My last change took advantage of that by using `map!` on it. `configs` is called quite often, including in this `[]` method, so there's a benefit to memoizing it. Back in `[]`, logically we are trying to find the first Hash in `configs` that has a value for the given key. Currently, we end up `map` and `compact` to just get that value. Instead, we can use a loop over `configs`, and break when we find the value for the key.
4 tasks
matzbot
pushed a commit
to ruby/ruby
that referenced
this pull request
Aug 30, 2023
…e and memory usage I previously identified and improved this method over in rubygems/rubygems#6884 but while reviewing another memory_profiler profile, I realized another gain we can eek out. This method keeps comes up in part because `configs` is allocating a new Hash every time. My last change took advantage of that by using `map!` on it. `configs` is called quite often, including in this `[]` method, so there's a benefit to memoizing it. Back in `[]`, logically we are trying to find the first Hash in `configs` that has a value for the given key. Currently, we end up `map` and `compact` to just get that value. Instead, we can use a loop over `configs`, and break when we find the value for the key. rubygems/rubygems@b913cfc87b
deivid-rodriguez
pushed a commit
that referenced
this pull request
Sep 21, 2023
Improve memory usage in Bundler::Settings, and thus improve boot time (cherry picked from commit 06231fd)
deivid-rodriguez
pushed a commit
that referenced
this pull request
Sep 21, 2023
Improve memory usage in Bundler::Settings, and thus improve boot time (cherry picked from commit 06231fd)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What was the end-user or developer problem that led to this PR?
I was running memory_profiler on our Rails app boot-time, and saw some opportunities.
What is your fix for the problem, implemented in this PR?
I used this code to scope memory allocations in our rails app to just bundler:
And then compared it with these changes by adding adding calling it with
ruby -Ipath/to/checkout/rubygems/bundler/lib
.Memory
Before:
After:
Runtime
For runtime, I with the same file above, but without the memory_profiling:
I used hyperfine to compare before/after:
hyperfine "ruby boot-time-benchmark.rb" "ruby -I/Users/josh.nichols/workspace/rubygems/bundler/lib boot-time-benchmark.rb"
:Summary
This reduces the amount of memory allocated during Rails startup in our app by 52%, from 4_883_872 bytes to 2_326_771 bytes.
It also reduces startup time by 6%, from 8.807s to 8.256s.
Make sure the following tasks are checked