Rails 5.2 adds bootsnap to the app to speed up boot time

Prathamesh Sonpatki

Prathamesh Sonpatki

January 1, 2018

This blog is part of our  Rails 5.2 series.

Rails 5.2 beta 1 was recently released.

If we generate a new Rails app using Rails 5.2, we will see bootsnap gem in the Gemfile. bootsnap helps in reducing the boot time of the app by caching expensive computations.

In a new Rails 5.2 app, boot.rb will contain following content:

1ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
2
3require 'bundler/setup' # Set up gems listed in the Gemfile.
4require 'bootsnap/setup' # Speed up boot time by caching expensive operations.
5
6if %w[s server c console].any? { |a| ARGV.include?(a) }
7  puts "=> Booting Rails"
8end

This sets up bootsnap to start in all environments. We can toggle it per environment as required.

This works out of the box and we don't have do to anything for the new app.

If we are upgrading an older app which already has bootsnap, then we need to make sure that we are using bootsnap >= 1.1.0 because new Rails apps ship with that version constraint.

If the app doesn't contain the bootsnap gem already then we will need to add it manually since rails app:update task adds the bootsnap/setup line to boot.rb regardless of its presence in the Gemfile.

If this blog was helpful, check out our full blog archive.

Stay up to date with our blogs.

Subscribe to receive email notifications for new blog posts.