Skip to content
This repository has been archived by the owner on Apr 27, 2021. It is now read-only.
/ bootscale Public archive
forked from byroot/bootscale

Speedup applications boot by caching require calls

License

Notifications You must be signed in to change notification settings

Shopify/bootscale

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

71 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bootscale

Build Status Gem Version

Speedup applications boot by caching file locations during require calls.

Speed gain depends on your number of gems. Under 100 gems you likely won't see the difference, but for bigger applications it can save 1 to 3 seconds of boot time per 100 used gems.

Installation

# Gemfile
gem 'bootscale', require: false

Then you need to add right after require 'bundler/setup':

require 'bundler/setup'
require 'bootscale/setup'

If your application is a Rails application, you will find this in config/boot.rb.

Important

For correctness cache should be updated everytime $LOAD_PATH is modified by calling Bootscale.regenerate.

For Rails apps it means adding an initializer in config/application.rb.

module MyApp
  class Application < Rails::Application
    initializer :regenerate_require_cache, before: :load_environment_config do
      Bootscale.regenerate
    end
  end
end

Faster cache loading

In order to gain ~10-30ms of extra load speed, you can use the msgpack gem:

# Gemfile
gem 'msgpack',   require: false
gem 'bootscale', require: false
# config/application.rb (or wherever you have the require of bundler/setup)
require 'bundler/setup'
require 'msgpack'
require 'bootscale/setup'

Under the hood

Bootscale caches the absolute location of all requirable files on the $LOAD_PATH and patches require + autoload to use these absolute paths, thereby avoiding having to check all load paths for every require.

Problem outlined in this talk

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/byroot/bootscale.

Local development: your load time will be very slow when using a local copy for development like gem 'bootscale', path: '~/Code/bootscal', use via git instead.

Thanks to Aaron Patterson for the idea of converting relative paths to absolute paths.

About

Speedup applications boot by caching require calls

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 81.5%
  • HTML 14.3%
  • CSS 2.0%
  • JavaScript 1.9%
  • Shell 0.3%