How Bootsnap optimizes Ruby performance
mainBootsnap optimizes Ruby application boot times through two primary mechanisms:
- Path Pre-Scanning: Modifies
Kernel#requireandKernel#loadto eliminate expensive$LOAD_PATHscans. It uses a cache to immediately resolve the full expanded path of a required file, avoiding multiple failed filesystem lookups. - Compilation Caching:
- Caches Ruby bytecode compilation results via
RubyVM::InstructionSequence.load_iseq. - Caches
YAML.load_fileandJSON.load_fileresults by converting them into a faster MessagePack (or Marshal) format.
- Caches Ruby bytecode compilation results via
Path entries are classified as stable (e.g., Ruby install prefix, Gem.path, or Bundler.bundle_path) which do not expire, or volatile (everything else) which are re-scanned every 30 seconds.