BlogsShopifyRuby App Boot Time Optimization

Ruby App Boot Time Optimization

Ruby App Boot Time Optimization

2
posts
2017–2020

This feature thread tracks the development and enhancement of Ruby application boot time optimization at Shopify. Initial efforts focused on addressing the substantial time spent waiting for Rails to boot in the monolithic application, impacting developer iteration speed. This post details the introduction of Bootsnap, a gem that optimizes and caches expensive computations by implementing path pre-scanning for `Kernel#require` and `ActiveSupport` autoloads, and compilation caching for Ruby bytec. This post further details approaches to identifying and fixing slow code through profiling (using tools like rbspy, stackprof, rack-mini-profiler, and app_profiler) and benchmarking (using Benchmark module, bm, bmbm, and benchmark-ips). It provides case studies on using these techniques to address performance regressions, such as unnecessary GC cycles caused by object allocation issues.

2020

How to Fix Slow Code in Ruby - Shopify

5/8/2020

This post details approaches to identifying and fixing slow code through profiling (using tools like rbspy, stackprof, rack-mini-profiler, and app_profiler) and benchmarking (using Benchmark module, bm, bmbm, and benchmark-ips). It provides case studies on using these techniques to address performance regressions, such as unnecessary GC cycles caused by object allocation issues.

2017

Bootsnap: Optimizing Ruby App Boot Time - Shopify

5/18/2017

This post introduces Bootsnap, a gem that optimizes Ruby application boot time by implementing two main strategies: path pre-scanning and compilation caching. Path pre-scanning optimizes `Kernel#require` and `ActiveSupport` autoloads by caching `$LOAD_PATH` scans and `ActiveSupport::Dependencies.autoload_paths` scans, reducing filesystem accesses. Compilation caching leverages `RubyVM::InstructionSequence.load_iseq` to cache Ruby bytecode compilation results and `YAML.load_file` to cache YAML deserialization into MessagePack format, bypassing expensive compilation and parsing steps on subsequent loads. The post details the technical implementation of these caching mechanisms, including cache invalidation strategies and the use of extended file attributes (xattrs) for storing compiled bytecode. It also presents performance results showing significant boot time reductions for various application sizes.