Why is Homebrew so slow? #1177
-
Non-network operations took one second!
hyperfine '/bin/bash /usr/local/bin/brew help' --warmup 1
# Benchmark #1: /bin/bash /usr/local/bin/brew help
# Time (mean ± σ): 964.8 ms ± 7.0 ms [User: 514.7 ms, System: 433.3 ms]
# Range (min … max): 953.4 ms … 973.6 ms 10 runs
hyperfine '/bin/bash /usr/local/bin/brew list' --warmup 1
# Benchmark #1: /bin/bash /usr/local/bin/brew list
# Time (mean ± σ): 1.151 s ± 0.031 s [User: 622.7 ms, System: 509.2 ms]
# Range (min … max): 1.125 s … 1.210 s 10 runs Would using POSIX-compliant dash (preinstalled on macOS) improve performance? |
Beta Was this translation helpful? Give feedback.
Replies: 14 comments 20 replies
-
It's busy, that is why it's slow. What kind of real world use-case do you have that needs speed optimization upon this? |
Beta Was this translation helpful? Give feedback.
-
My guess would be probably not. Interestingly, from the numbers above, the CPU time for You can find the code that drives |
Beta Was this translation helpful? Give feedback.
-
Ubuntu 20.04 with Intel J5005 CPU @ 1.50GHz hyperfine 'apt list --installed'
# Benchmark #1: apt list --installed
# Time (mean ± σ): 470.4 ms ± 4.4 ms [User: 436.0 ms, System: 34.5 ms]
# Range (min … max): 462.3 ms … 477.5 ms |
Beta Was this translation helpful? Give feedback.
-
I always assumed that Brew was slow because Ruby was slow. There are similar issues with CLI tools built in Python and NodeJS, where lots of little inefficiencies in the language runtime compound into really big overhead even for simple tasks. Compare NVM and Rbenv to FNM and Frum; it's night and day. Apparently Ruby 3.0 is quite a bit faster, and there are also faster (albeit experimental) Ruby implementations that use either JIT compiling or traditional ahead-of-time compiling using Sorbet type annotations. Has anyone experimented with running Brew under those runtimes? |
Beta Was this translation helpful? Give feedback.
-
You could profile it to see why it's slow, then propose a fix. Here's one from me: convert code base to crystal (if it's cpu bound that is) ? :) |
Beta Was this translation helpful? Give feedback.
-
Homebrew is a piece of unusable software |
Beta Was this translation helpful? Give feedback.
-
It's the git fetch. If you're on a slow connection and haven't updated your git repo clone for a while, it's going to take a loooooong time. |
Beta Was this translation helpful? Give feedback.
-
Brew might be downloading something large. |
Beta Was this translation helpful? Give feedback.
-
Well, Homebrew is indeed not among the fastest package managers, especially if any the operation network dependent (even if your corporate leased line is 10Gb/s. That's something the maintainers have to first admit to attempt a fix 😞 Anyway, if someone stumbles across this thread when trying to perform network dependent operations (install, upgrade etc.) and wondering why brew is compiling almost everything, make sure the version of the OS is supported. FAQ on this makes sense. |
Beta Was this translation helpful? Give feedback.
-
It's amazing how shitty a piece of software may get to be, after a few minutes, when I noticed brew was going nowhere "trying" to install php8.1, becaue stupid brew upgraded to 8.2 without asking me, and while it was downloading a lot of useless and non necessary "dependencies" I was able to download and install MacPorts and finish a php installation with it. |
Beta Was this translation helpful? Give feedback.
-
Just tried to install |
Beta Was this translation helpful? Give feedback.
-
Months after removing this crap I still find orphan files scattered all around my system!! I did mention uninstalling was gonna be fun, and you guys did not disappoint! |
Beta Was this translation helpful? Give feedback.
-
I literally just spent 5 hours trying to install and symlink node and npm (probably because my OS is outdated). And it still failed. After 5 hours. |
Beta Was this translation helpful? Give feedback.
-
On MacOS |
Beta Was this translation helpful? Give feedback.
My guess would be probably not.
brew list
may be slower than it could be due to how some of the logic is overloaded - it's not used just for listing installed items, but also can filter by formulae only, casks only, unbrewed formulae, versions of a particular formula, pinned formulae only, etc.Interestingly, from the numbers above, the CPU time for
brew
shows thatSystem
time makes up the majority ofUser
time, whilepip
shows aSystem
time that is about a third that of theUser
time.You can find the code that drives
brew list
here. If you have a proposal on how to make thebrew list
command run faster, plea…