Brew: `brew --prefix <package>` is much slower than `brew --prefix`

Created on 2 Aug 2020  Â·  8Comments  Â·  Source: Homebrew/brew

  • [X] ran brew update and can still reproduce the problem?
  • [X] ran brew doctor, fixed all issues and can still reproduce the problem?
  • [X] ran brew config and brew doctor and included their output with your issue?

What you were trying to do (and why)

Edit my .zshrc to use a brew-installed package

What happened (include command output)

My .zshrc ran very slowly. It appears brew --prefix <package> takes almost a second,

time brew --prefix openssl
/usr/local/opt/[email protected]
brew --prefix openssl  0.76s user 0.54s system 92% cpu 1.412 total
time brew --prefix bzip2
/usr/local/opt/bzip2
brew --prefix bzip2  0.73s user 0.47s system 92% cpu 1.288 total
time brew --prefix autoconf
/usr/local/opt/autoconf
brew --prefix autoconf  0.79s user 0.55s system 90% cpu 1.483 total
## What you expected to happen I expect `brew --prefix ` to run about as fast as `brew --prefix`, which takes 0.02 seconds.
$ time brew --prefix
/usr/local
brew --prefix  0.02s user 0.03s system 77% cpu 0.062 total
## Step-by-step reproduction instructions (by running `brew` commands)
brew install openssl
time brew --prefix openssl
## Output of `brew config` and `brew doctor` commands NB: although this is on a beta MacOS version, I strongly suspect the issue is not limited to it.
HOMEBREW_VERSION: 2.4.9-164-gdf16e9f
ORIGIN: https://github.com/Homebrew/brew
HEAD: df16e9f2de5df897f2a4ae95b1a40edc54dfc1b8
Last commit: 8 hours ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: 16a20d5f3c9a9868f61f312b62c2cb6e1f27c53a
Core tap last commit: 29 minutes ago
HOMEBREW_PREFIX: /usr/local
HOMEBREW_EDITOR: subl -w
HOMEBREW_MAKE_JOBS: 4
CPU: quad-core 64-bit haswell
Homebrew Ruby: 2.6.3 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
Clang: 12.0 build 1200
Git: 2.24.3 => /Library/Developer/CommandLineTools/usr/bin/git
Curl: 7.64.1 => /usr/bin/curl
Java: 14.0.2
macOS: 11.0-x86_64
CLT: 12.0.0.0.1.1595091463
Xcode: N/A


Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!

Warning: You are using macOS 11.0.
We do not provide support for this pre-release version.
You will encounter build failures with some formulae.
Please create pull requests instead of asking for help on Homebrew's GitHub,
Discourse, Twitter or IRC. You are responsible for resolving any issues you
experience while you are running this pre-release version.

Most helpful comment

brew --prefix <formula> needs Ruby, but brew --prefix has a bash shortcut with a Ruby fallback. brew prof calls the Ruby version in both cases.

All 8 comments

We'd accept a pull request to improve the speed, but no maintainers are working on this currently. See brew prof to use the Ruby profiler to see where things are slow.

I’ve given up on trying to fix this. In my personal shell profile, I now eval "$(brew shellenv)", and I’ve replaced all invocations of brew --prefix _FORMULA_ with:

"${HOMEBREW_PREFIX:-$(brew --prefix)}/opt/nvm"

@jonchang Seems like brew prof is functionally broken:

$ brew prof --prefix openssl
Usage: brew prof command

Run Homebrew with the Ruby profiler, e.g. brew prof readall.

    -q, --quiet                      Suppress any warnings.
    -v, --verbose                    Make some output more verbose.
    -d, --debug                      Display any debugging information.
    -h, --help                       Show this message.
Error: invalid option: --prefix

Opened #8192 to fix that.

Thanks, @Bo98. Using your code I was able to make some traces. But the data doesn't tell me much, largely because I have no idea what I'm doing in Ruby. prof.zip

Strangely, running this with prof closes the absolute time difference between --prefix and --prefix <pkg>. I think that some heavy modules are being instantiated with brew --prefix <pkg>, and the interpreter causes this to be cached.

Whatever it is, the stack profile just looks like a tower of Kernel#require followed by a tiiiiny bit of application code.
image
image

➜  ~ time brew --prefix
/usr/local
brew --prefix  0.01s user 0.02s system 78% cpu 0.050 total
➜  ~ time brew --prefix openssl
/usr/local/opt/[email protected]
brew --prefix openssl  0.87s user 0.52s system 92% cpu 1.499 total
➜  ~ time brew prof --prefix        
/usr/local
brew prof --prefix  3.44s user 1.13s system 97% cpu 4.687 total
➜  ~ time brew prof --prefix openssl
/usr/local/opt/[email protected]
brew prof --prefix openssl  3.75s user 1.24s system 97% cpu 5.112 total

brew --prefix <formula> needs Ruby, but brew --prefix has a bash shortcut with a Ruby fallback. brew prof calls the Ruby version in both cases.

Thank, @jonchang! That makes a lot of sense. So I guess this would be huge project to make performant :-(

So I guess this would be huge project to make performant :-(

Yes. The issue is Homebrew's "boot time" due to gem usage e.g. ActiveSupport.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rtobrien picture rtobrien  Â·  3Comments

cfredhart picture cfredhart  Â·  4Comments

JustinTArthur picture JustinTArthur  Â·  3Comments

Rotonen picture Rotonen  Â·  4Comments

javian picture javian  Â·  4Comments