I write code that supports a lot of other developers, and try to provide a seamless installation experience. To provide portable installation instructions that work with Homebrew installations on every user's machine, I need to find the Homebrew root directory using brew --prefix.
However, that's really slow; running time brew --prefix ten times on a 2015 Macbook Pro with 16GB RAM yielded results between 184ms and 347ms (it sped up as I ran it more often, though the uncached time is also important). This makes it infeasible to put at e.g. the top of a Makefile, or to use the output from brew --prefix as part of a Make target.
Is there a way we can speed it up? 95% of the time I feel like the answer is /usr/local; can we optimize for that case? Can we store the answer in a file somewhere and check that before doing expensive work? (I can build caching myself/for the users I support but it would be a little more cumbersome than building it into Homebrew).
I write code that supports a lot of other developers, and try to provide a seamless installation experience. To provide portable installation instructions that work with Homebrew installations on every user's machine, I need to find the Homebrew root directory using
brew --prefix.However, that's really slow; running
time brew --prefixten times on a 2015 Macbook Pro with 16GB RAM yielded results between 184ms and 347ms (it sped up as I ran it more often, though the uncached time is also important). This makes it infeasible to put at e.g. the top of a Makefile, or to use the output frombrew --prefixas part of a Make target.Is there a way we can speed it up? 95% of the time I feel like the answer is
/usr/local; can we optimize for that case? Can we store the answer in a file somewhere and check that before doing expensive work? (I can build caching myself/for the users I support but it would be a little more cumbersome than building it into Homebrew).