Skip to content

Conversation

@MikeMcQuaid
Copy link
Member

I noticed a tiny performance improvement here when reviewing #21351 where we can avoid creating a Formula when loading a Tab from a name/rack path.

I noticed a tiny performance improvement here where we can avoid
creating a `Formula` when loading a Tab from a name/rack path.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR optimizes Tab.for_name to avoid unnecessarily creating a Formula object when loading a Tab from a name/rack path, by preferring to use a Keg directly when one is available.

  • Extracts common keg selection logic from Formulary.from_rack into a new Keg.from_rack method
  • Modifies Tab.for_name to call Keg.from_rack first and only fall back to Formulary.from_rack when no keg exists
  • Updates Formulary.from_rack to accept an optional keg parameter to avoid redundant keg lookups

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
Library/Homebrew/keg.rb Adds new Keg.from_rack class method that returns the linked, optlinked, or latest keg from a rack
Library/Homebrew/tab.rb Refactors Tab.for_name to use Keg.from_rack first, avoiding formula creation when a keg is found
Library/Homebrew/formulary.rb Updates from_rack to accept optional keg parameter with default value, eliminating duplicate keg selection logic

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Member

@Rylan12 Rylan12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, makes sense!

@MikeMcQuaid MikeMcQuaid added this pull request to the merge queue Jan 2, 2026
Merged via the queue into main with commit 718f6bf Jan 2, 2026
43 checks passed
@MikeMcQuaid MikeMcQuaid deleted the improve_tab_for_name branch January 2, 2026 20:05
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.

3 participants