Skip to content

Record startup phases in brew prof --timings - #23526

Merged
MikeMcQuaid merged 1 commit into
mainfrom
perf_improvements
Aug 14, 2026
Merged

Record startup phases in brew prof --timings#23526
MikeMcQuaid merged 1 commit into
mainfrom
perf_improvements

Conversation

@MikeMcQuaid

Copy link
Copy Markdown
Member
  • startup ended after require "global" and the next event was api_metadata_load, hiding ~130ms of a ~260ms warm no-op install
  • command_load covers Commands.valid_internal_cmd?, which requires the command's file and so pays for its whole require graph: at ~90-135ms this is the single largest phase of brew install
  • cli_parse covers both the top-level parse and cmd_class.new, the latter being where named args inflate formulae
  • measure now no-ops until start! runs, so the startup path can measure unconditionally; require "json" moves into write!

This will help with future performance optimisation work.


  • Have you followed our Contributing guidelines?
  • Have you checked for other open Pull Requests for the same change?
  • Have you explained what your changes do? Performance claims (e.g. "this is faster") must include Hyperfine benchmarks.
  • Have you explained why you'd like these changes included, not just what they do?
  • For bug fixes, have you given step-by-step brew commands to reproduce the bug?
  • Have you written new tests (excluding integration tests)? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) locally?

  • I did not use AI/LLM to create this PR, or I disclosed the tool/model below and reviewed its output; I did not attribute commits to AI and will answer maintainer questions and review comments myself without AI/LLM.

Claude Opus 5 high with local review and testing.


- `startup` ended after `require "global"` and the next event was
  `api_metadata_load`, hiding ~130ms of a ~260ms warm no-op install
- `command_load` covers `Commands.valid_internal_cmd?`, which requires
  the command's file and so pays for its whole `require` graph: at
  ~90-135ms this is the single largest phase of `brew install`
- `cli_parse` covers both the top-level parse and `cmd_class.new`,
  the latter being where named args inflate formulae
- `measure` now no-ops until `start!` runs, so the startup path can
  measure unconditionally; `require "json"` moves into `write!`
Copilot AI lite review requested due to automatic review settings August 14, 2026 15:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 improves brew prof --timings phase visibility during early startup by making phase measurement safe to call unconditionally and by adding new startup-focused timing phases to brew.rb, enabling more actionable performance breakdowns.

Changes:

  • Make Homebrew::PhaseTimings.measure a no-op until start! has enabled recording, and defer require "json" until write!.
  • Add cli_parse and command_load timing measurements in Library/Homebrew/brew.rb to capture CLI parsing and command require-graph loading time.
  • Update brew prof --timings integration expectations to include the new phases.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
Library/Homebrew/utils/phase_timings.rb Make measurement opt-in and defer JSON loading until writing output.
Library/Homebrew/brew.rb Add new startup-phase timing measurements (cli_parse, command_load).
Library/Homebrew/test/dev-cmd/prof_spec.rb Adjust integration test to expect the new timing phases.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment thread Library/Homebrew/test/dev-cmd/prof_spec.rb
@MikeMcQuaid
MikeMcQuaid enabled auto-merge August 14, 2026 16:30
@MikeMcQuaid
MikeMcQuaid added this pull request to the merge queue Aug 14, 2026
Merged via the queue into main with commit d95d5be Aug 14, 2026
47 checks passed
@MikeMcQuaid
MikeMcQuaid deleted the perf_improvements branch August 14, 2026 16:49
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