Skip to content

Homebrew startup performance tweaks#21734

Merged
MikeMcQuaid merged 1 commit intomainfrom
startup_performance
Mar 14, 2026
Merged

Homebrew startup performance tweaks#21734
MikeMcQuaid merged 1 commit intomainfrom
startup_performance

Conversation

@MikeMcQuaid
Copy link
Member

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.


  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) with your changes locally?

  • AI was used to generate or assist with generating this PR. Please specify below how you used AI to help you, and what steps you have taken to manually verify the changes.

Used OpenAI Codex to test with manual testing and human review passes on both high-level approach and specific code changes.


Copilot AI review requested due to automatic review settings March 14, 2026 16:21
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 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/brew startup by avoiding dirname and 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.rb command 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.
@MikeMcQuaid MikeMcQuaid force-pushed the startup_performance branch from 73a7816 to 1730ec2 Compare March 14, 2026 16:43
@MikeMcQuaid MikeMcQuaid enabled auto-merge March 14, 2026 16:43
@MikeMcQuaid MikeMcQuaid added this pull request to the merge queue Mar 14, 2026
Merged via the queue into main with commit d56e75d Mar 14, 2026
38 checks passed
@MikeMcQuaid MikeMcQuaid deleted the startup_performance branch March 14, 2026 17:30

if [[ -n "${HOMEBREW_MACOS}" ]]
then
HOMEBREW_MACOS_VERSION="$(/usr/bin/sw_vers -productVersion)"
Copy link
Member

Choose a reason for hiding this comment

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

Looks like this is now set too late for shellenv:

[[ "${HOMEBREW_MACOS_VERSION_NUMERIC}" -ge "140000" ]] &&

Copy link
Member Author

Choose a reason for hiding this comment

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

@Bo98 Whoops: #21752

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.

4 participants