-
-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
tap: fix performance regression in *_files_by_name #16791
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -820,7 +820,7 @@ | |
|
||
sig { returns(T::Hash[String, T::Array[String]]) } | ||
def self.reverse_tap_migrations_renames | ||
Tap.each_with_object({}) do |tap, hash| | ||
cache[:reverse_tap_migrations_renames] ||= Tap.each_with_object({}) do |tap, hash| | ||
tap.tap_migrations.each do |old_name, new_name| | ||
new_tap_user, new_tap_repo, new_name = new_name.split("/", 3) | ||
next unless new_name | ||
|
@@ -1211,14 +1211,16 @@ | |
def formula_files_by_name | ||
return super if Homebrew::EnvConfig.no_install_from_api? | ||
|
||
tap_path = path.to_s | ||
Homebrew::API::Formula.all_formulae.each_with_object({}) do |item, hash| | ||
name, formula_hash = item | ||
# If there's more than one item with the same path: use the longer one to prioritise more specific results. | ||
existing_path = hash[name] | ||
# Pathname equivalent is slow in a tight loop | ||
new_path = File.join(tap_path, formula_hash.fetch("ruby_source_path")) | ||
hash[name] = Pathname(new_path) if existing_path.nil? || existing_path.to_s.length < new_path.length | ||
@formula_files_by_name ||= begin | ||
tap_path = path.to_s | ||
Homebrew::API::Formula.all_formulae.each_with_object({}) do |item, hash| | ||
name, formula_hash = item | ||
# If there's more than one item with the same path: use the longer one to prioritise more specific results. | ||
existing_path = hash[name] | ||
# Pathname equivalent is slow in a tight loop | ||
new_path = File.join(tap_path, formula_hash.fetch("ruby_source_path")) | ||
hash[name] = Pathname(new_path) if existing_path.nil? || existing_path.to_s.length < new_path.length | ||
end | ||
end | ||
end | ||
|
||
|
@@ -1279,7 +1281,7 @@ | |
def cask_files_by_name | ||
return super if Homebrew::EnvConfig.no_install_from_api? | ||
|
||
Homebrew::API::Cask.all_casks.each_with_object({}) do |item, hash| | ||
@cask_files_by_name ||= Homebrew::API::Cask.all_casks.each_with_object({}) do |item, hash| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, we probably should avoid Pathname here too There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. |
||
name, cask_hash = item | ||
# If there's more than one item with the same path: use the longer one to prioritise more specific results. | ||
existing_path = hash[name] | ||
|
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.
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.
@apainintheneck, I remember specifically not caching this because it will never be cleared, except in tests.
Basically, every instance's
#clear_cache
would need to clear the globalcache[:reverse_tap_migrations_renames]
, because it depends on all taps.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.
My understanding is that
Tap.reverse_tap_migrations_renames
loads each tap withTap.each
and then callsTap#tap_migrations
on each tap to build this list. Do we expect eitherTap.each
orTap#tap_migrations
to change over the life of the program?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.
I guess you're worried about the case where a tap gets installed with
Tap#ensure_installed!
afterTap.reverse_tap_migrations_renames
has been built, right? Maybe it'd just be a good idea to clear the class level cache when we do that sinceTap#ensure_installed!
should only very rarely need to install a new tap.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.
Or we could just go back to how things are. Either way works for me.
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.
Could just have the cache inside the
Tap.each_with_object
instead and cache bycache[:reverse_tap_migrations_renames][tap.name]
, or have an instance method so it's tied to instance cache.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.
Now that I look at it a bit more the problem might be
Tap.each
in this case.This is from running
brew prof -- deps --casks --eval-all
.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.
A special cache of installed tap instances that gets reset on
Tap#install
andTap#uninstall
would make sense to me.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.
That sounds doable. I'm not sure how that could be implemented in a simple, straightforward way though. This seemed like a no-brainer but now I know it wasn't.
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.
@Bo98 @apainintheneck @reitermarkus I think we should/could just nuke all tap caches on those methods given how infrequently they are called.