Homebrew startup performance tweaks#21734
Merged
MikeMcQuaid merged 1 commit intomainfrom Mar 14, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR targets improved cold startup performance for common brew invocations by deferring or hoisting work out of hot paths in the shell and Ruby entrypoints.
Changes:
- Optimize
bin/brewstartup by avoidingdirnameand by precomputing the exported-vars exclusion regex once. - Defer more expensive initialization in
brew.sh(e.g., macOS version parsing, wrapper checks, curl setup) until it’s actually needed. - Refactor
brew.rbcommand detection/dispatch to reduce work on startup and avoid repeated external command path lookups.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
bin/brew |
Replaces dirname with parameter expansion in symlink resolution; hoists env-file exported-var regex construction. |
Library/Homebrew/brew.sh |
Defers wrapper checking and macOS version parsing; moves setup_curl and default domain initialization later. |
Library/Homebrew/brew.rb |
Refactors command parsing and external command detection to reduce startup work. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Move some stuff around to improve cold startup performance. `brew --prefix` went from about 16.5 ms to 9.0 ms `brew help` went from about 16.5 ms to 8.7 ms.
73a7816 to
1730ec2
Compare
p-linnane
approved these changes
Mar 14, 2026
Bo98
reviewed
Mar 17, 2026
|
|
||
| if [[ -n "${HOMEBREW_MACOS}" ]] | ||
| then | ||
| HOMEBREW_MACOS_VERSION="$(/usr/bin/sw_vers -productVersion)" |
Member
There was a problem hiding this comment.
Looks like this is now set too late for shellenv:
brew/Library/Homebrew/cmd/shellenv.sh
Line 31 in aba2263
Member
Author
This file contains hidden or 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
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.
Move some stuff around to improve cold startup performance.
brew --prefixwent from about 16.5 ms to 9.0 msbrew helpwent from about 16.5 ms to 8.7 ms.brew lgtm(style, typechecking and tests) with your changes locally?Used OpenAI Codex to test with manual testing and human review passes on both high-level approach and specific code changes.