-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Avoid allocating empty hashes in Index #6962
Avoid allocating empty hashes in Index #6962
Conversation
Since the hashes have a default proc that returns a (new) empty hash, we can avoid allocating those empty hashes when we are only doing lookups. Test from running `bundle update --bundler` against a rails app I have lying around: ``` ==> memprof.after.txt <== Total allocated: 9.71 MB (68282 objects) Total retained: 4.87 MB (33791 objects) ==> memprof.before.txt <== Total allocated: 10.83 MB (100596 objects) Total retained: 5.02 MB (34721 objects) ```
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great find, thanks @segiddins!
76da335
to
f1ec56c
Compare
bundler/lib/bundler/index.rb
Outdated
@@ -170,31 +160,41 @@ def add_source(index) | |||
|
|||
private | |||
|
|||
def search_by_query(query) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There were no callers except the one here. Moved to private and changed to return nil when nothing found so calling code can more easily reduce array usage.
f1ec56c
to
e6f2146
Compare
21aed21
to
c8eb2f1
Compare
Remove the default nested hash in Index entirely Index#search_all now yields or returns enum since that's what caller needs.
c8eb2f1
to
c45ea3b
Compare
…ty-hashes-in-index Avoid allocating empty hashes in Index (cherry picked from commit bf1c85d)
…ty-hashes-in-index Avoid allocating empty hashes in Index (cherry picked from commit bf1c85d)
* `Bundler::Fetcher#fetchers` was made private at rubygems/rubygems#6919. * `Bundler::Index#search_all` returns an enumerator since rubygems/rubygems#6962.
* `Bundler::Fetcher#fetchers` was made private at rubygems/rubygems#6919. * `Bundler::Index#search_all` returns an enumerator since rubygems/rubygems#6962.
* `Bundler::Fetcher#fetchers` was made private at rubygems/rubygems#6919. * `Bundler::Index#search_all` returns an enumerator since rubygems/rubygems#6962.
Since the hashes have a default proc that returns a (new) empty hash, we
can avoid allocating those empty hashes when we are only doing lookups.
Test from running
bundle update --bundler
against a rails app I havelying around:
What was the end-user or developer problem that led to this PR?
What is your fix for the problem, implemented in this PR?
Make sure the following tasks are checked