Record startup phases in brew prof --timings - #23526
Merged
Merged
Conversation
- `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!`
Contributor
There was a problem hiding this comment.
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.measurea no-op untilstart!has enabled recording, and deferrequire "json"untilwrite!. - Add
cli_parseandcommand_loadtiming measurements inLibrary/Homebrew/brew.rbto capture CLI parsing and command require-graph loading time. - Update
brew prof --timingsintegration 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.
MikeMcQuaid
enabled auto-merge
August 14, 2026 16:30
p-linnane
approved these changes
Aug 14, 2026
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.
startupended afterrequire "global"and the next event wasapi_metadata_load, hiding ~130ms of a ~260ms warm no-op installcommand_loadcoversCommands.valid_internal_cmd?, which requires the command's file and so pays for its wholerequiregraph: at ~90-135ms this is the single largest phase ofbrew installcli_parsecovers both the top-level parse andcmd_class.new, the latter being where named args inflate formulaemeasurenow no-ops untilstart!runs, so the startup path can measure unconditionally;require "json"moves intowrite!This will help with future performance optimisation work.
brewcommands to reproduce the bug?brew lgtm(style, typechecking and tests) locally?Claude Opus 5 high with local review and testing.