Skip to content

info: avoid Formula/Cask objects for counts#21963

Open
MikeMcQuaid wants to merge 1 commit intomainfrom
info-perf-avoid-formula-objects
Open

info: avoid Formula/Cask objects for counts#21963
MikeMcQuaid wants to merge 1 commit intomainfrom
info-perf-avoid-formula-objects

Conversation

@MikeMcQuaid
Copy link
Copy Markdown
Member

  • use Tab runtime_dependencies hashes and rack directory existence instead of instantiating Formula or Cask objects for dependency/dependent counts
  • replace rack.subdirs.max_by mtime stat calls with rack.subdirs.last since dep names rarely change across versions
  • skip JSON parsing in count_installed_dependents when the formula name doesn't appear in the raw receipt file
  • skip dependent counting entirely for non-TTY output
mike book # hyperfine --prepare "git checkout a93c2bbf023fbfb1f52324eb8652c5be941ee2e0" "OLD=1 brew info ruby" --prepare "git checkout main" "CURRENT=1 brew info ruby" --prepare "git checkout info-perf-avoid-formula-objects" "NEW=1 brew info ruby"
Benchmark 1: OLD=1 brew info ruby
  Time (mean ± σ):     974.4 ms ± 131.9 ms    [User: 545.4 ms, System: 227.4 ms]
  Range (min … max):   864.0 ms … 1336.1 ms    10 runs
 
Benchmark 2: CURRENT=1 brew info ruby
  Time (mean ± σ):      1.345 s ±  0.138 s    [User: 0.890 s, System: 0.264 s]
  Range (min … max):    1.235 s …  1.722 s    10 runs
  
Benchmark 3: NEW=1 brew info ruby
  Time (mean ± σ):     885.6 ms ±  29.3 ms    [User: 517.8 ms, System: 213.8 ms]
  Range (min … max):   845.3 ms … 929.1 ms    10 runs

  • 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 (excluding integration 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 Claude Code with manual review and testing.


Copilot AI review requested due to automatic review settings April 9, 2026 11:38
@MikeMcQuaid MikeMcQuaid enabled auto-merge April 9, 2026 11:38
Copy link
Copy Markdown
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

Optimizes brew info dependency/dependent counting by using installed keg Tab data and filesystem checks instead of instantiating Formula/Cask objects, reducing runtime overhead in interactive output.

Changes:

  • Add a receipt/tab-based dependent counting helper and use keg tab runtime_dependencies for recursive runtime counts.
  • Update cask dependency “installed?” checks to use Cellar/Caskroom directory existence.
  • Adjust specs to create minimal Cellar/Caskroom state to exercise the new code paths.

Reviewed changes

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

File Description
Library/Homebrew/cmd/info.rb Switches dependency/dependent counting to use Tab/Cellar inspection and adds a new counting helper.
Library/Homebrew/cask/info.rb Avoids loading Formula/Cask objects when determining whether dependencies are installed.
Library/Homebrew/test/cmd/info_spec.rb Updates formula info spec to build keg/tab fixtures in the Cellar.
Library/Homebrew/test/cask/info_spec.rb Updates cask info spec to create Caskroom directories for “installed” detection.

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

@MikeMcQuaid MikeMcQuaid force-pushed the info-perf-avoid-formula-objects branch 2 times, most recently from 0113887 to 446a930 Compare April 9, 2026 16:13
- use Tab `runtime_dependencies` hashes and rack
  directory existence instead of instantiating Formula
  or Cask objects for dependency/dependent counts
- use `Keg.from_rack` for stable keg selection instead
  of unsorted `rack.subdirs.last`
- strip tap prefix from dep names via `split("/").last`
  so tap-qualified names resolve to the correct rack
- skip JSON parsing in `count_installed_dependents`
  when the formula name doesn't appear in the raw
  receipt file
- skip dependent counting entirely for non-TTY output
@MikeMcQuaid MikeMcQuaid force-pushed the info-perf-avoid-formula-objects branch from 446a930 to 85f279d Compare April 9, 2026 16:51
@MikeMcQuaid MikeMcQuaid requested a review from cho-m April 9, 2026 20:21
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.

2 participants