brew/Library/Homebrew/load_path.rb
Mike McQuaid 683ae7ff53
Add HOMEBREW_BOOTSNAP to optionally use Bootsnap
> Bootsnap is a library that plugs into Ruby, with optional support
> for ActiveSupport and YAML, to optimize and cache expensive
> computations.
https://github.com/Shopify/bootsnap

For our case that translates to "repeated calls to `brew` have
reductions in the time spend `require`ing speeding up the process
boot time".

For example:

```
$ hyperfine --warmup=2 "unset HOMEBREW_BOOTSNAP; brew info wget" "export HOMEBREW_BOOTSNAP=1; brew info wget"
Benchmark #1: unset HOMEBREW_BOOTSNAP; brew info wget
  Time (mean ± σ):      2.417 s ±  0.032 s    [User: 659.0 ms, System: 855.5 ms]
  Range (min … max):    2.382 s …  2.464 s    10 runs

Benchmark #2: export HOMEBREW_BOOTSNAP=1; brew info wget
  Time (mean ± σ):      1.862 s ±  0.064 s    [User: 425.3 ms, System: 566.8 ms]
  Range (min … max):    1.736 s …  1.952 s    10 runs

Summary
  'export HOMEBREW_BOOTSNAP=1; brew info wget' ran
    1.30 ± 0.05 times faster than 'unset HOMEBREW_BOOTSNAP; brew info wget'
```
2021-01-21 12:34:04 +00:00

18 lines
336 B
Ruby

# typed: true
# frozen_string_literal: true
require "pathname"
HOMEBREW_LIBRARY_PATH = Pathname(__dir__).realpath.freeze
$LOAD_PATH.push HOMEBREW_LIBRARY_PATH.to_s
require "vendor/bundle/bundler/setup"
if ENV["HOMEBREW_BOOTSNAP"]
require "bootsnap"
else
$LOAD_PATH.select! { |d| Pathname(d).directory? }
$LOAD_PATH.uniq!
end