Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

brew.sh: cache HOMEBREW_VERSION on disk. #17292

Merged
merged 3 commits into from
May 14, 2024
Merged

Conversation

MikeMcQuaid
Copy link
Member

@MikeMcQuaid MikeMcQuaid commented May 14, 2024

This is a (relatively, for this Bash script) expensive operation that can be trivially cached so: let's do so.

Speedup on my machine:

$ hyperfine "brew --version" "HOMEBREW_VERSION_CACHE=1 brew --version"
Benchmark 1: brew --version
  Time (mean ± σ):     173.4 ms ±   5.1 ms    [User: 28.7 ms, System: 67.0 ms]
  Range (min … max):   167.3 ms … 182.9 ms    15 runs

Benchmark 2: HOMEBREW_VERSION_CACHE=1 brew --version
  Time (mean ± σ):     145.9 ms ±   4.0 ms    [User: 22.4 ms, System: 33.9 ms]
  Range (min … max):   140.0 ms … 154.5 ms    17 runs

Summary
  HOMEBREW_VERSION_CACHE=1 brew --version ran
    1.19 ± 0.05 times faster than brew --version

While we're here:

  • improve a comment
  • avoid shelling out to further improve performance in more cases

Library/Homebrew/brew.sh Outdated Show resolved Hide resolved
Library/Homebrew/brew.sh Outdated Show resolved Hide resolved
Library/Homebrew/brew.sh Outdated Show resolved Hide resolved
Comment on lines +821 to 832
# TODO: this is fairly slow, figure out if there's a faster way.
XCRUN_OUTPUT="$(/usr/bin/xcrun clang 2>&1)"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Bo98 any ideas for a faster command here? Wondering if there's anything else that can be run with xcrun, execute faster in the typical case but still produce the license issue otherwise 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the first time execution, most of the slowness is typically xcrun itself due to searching. If you're still seeing the issue on 2nd execution, try clear the license and see if any of these reproduce:

$ find /usr/bin -samefile /usr/bin/clang -exec basename {} \; | sort
DeRez
GetFileInfo
ResMerger
Rez
SetFile
SplitForks
ar
as
asa
bison
c++
c++filt
c89
c99
cc
clang
clang++
clangd
cmpdylib
codesign_allocate
cpp
ctags
ctf_insert
dsymutil
dwarfdump
flex
flex++
g++
gatherheaderdoc
gcc
gcov
git
git-receive-pack
git-shell
git-upload-archive
git-upload-pack
gm4
gnumake
gperf
hdxml2manxml
headerdoc2html
indent
install_name_tool
ld
lex
libtool
lipo
lldb
llvm-g++
llvm-gcc
lorder
m4
make
mig
nm
nmedit
objdump
otool
pagestuff
pip3
python3
ranlib
resolveLinks
rpcgen
segedit
size
sourcekit-lsp
strings
strip
swift
swiftc
unifdef
unifdefall
vtool
xml2man
yacc

(though ideally one that's already likely to be in the cache - or in the cache soon)

There's also defaults read /Library/Preferences/com.apple.dt.Xcode but then you're on a parade of finding the Xcode install to extract the version from.

Library/Homebrew/brew.sh Outdated Show resolved Hide resolved
MikeMcQuaid and others added 3 commits May 14, 2024 15:46
This is a (relatively, for this Bash script) expensive operation that
can be trivially cached so: let's do so.

Speedup on my machine:

```
$ hyperfine "brew --version" "HOMEBREW_VERSION_CACHE=1 brew --version"
Benchmark 1: brew --version
  Time (mean ± σ):     173.4 ms ±   5.1 ms    [User: 28.7 ms, System: 67.0 ms]
  Range (min … max):   167.3 ms … 182.9 ms    15 runs

Benchmark 2: HOMEBREW_VERSION_CACHE=1 brew --version
  Time (mean ± σ):     145.9 ms ±   4.0 ms    [User: 22.4 ms, System: 33.9 ms]
  Range (min … max):   140.0 ms … 154.5 ms    17 runs

Summary
  HOMEBREW_VERSION_CACHE=1 brew --version ran
    1.19 ± 0.05 times faster than brew --version
```

Co-authored-by: Bo Anderson <[email protected]>
@MikeMcQuaid MikeMcQuaid merged commit 801c737 into master May 14, 2024
25 checks passed
@MikeMcQuaid MikeMcQuaid deleted the homebrew_version_cache branch May 14, 2024 07:05
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.

None yet

3 participants