Skip to content

Instantly share code, notes, and snippets.

@toolmantim
Created October 17, 2017 02:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toolmantim/db189af6e12c84aa2d33c6a92dcc2840 to your computer and use it in GitHub Desktop.
Save toolmantim/db189af6e12c84aa2d33c6a92dcc2840 to your computer and use it in GitHub Desktop.
Before/after adding bootsnap
$ # Before bootsnap
$ time DISABLE_SPRING=1 bin/rails r 'exit 0'
real 0m7.030s
user 0m4.429s
sys 0m2.499s
$ # Adding bootsnap
$ git diff -u
diff --git a/Gemfile b/Gemfile
index b6b7854cf..445cb572f 100644
--- a/Gemfile
+++ b/Gemfile
@@ -7,6 +7,9 @@ source "https://rubygems.org"
# production to load env variables into the app.
gem "dotenv"
+# For speeding up the Ruby/require boot process
+gem 'bootsnap', require: false
+
# Include rails gems individually so we don't include `actioncable`
gem "activerecord"
gem "actionpack"
diff --git a/Gemfile.lock b/Gemfile.lock
index c10976b46..09a3da63b 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -74,6 +74,8 @@ GEM
base62-rb (0.3.1)
bcrypt (3.1.11)
benchmark-ips (2.7.2)
+ bootsnap (1.1.5)
+ msgpack (~> 1.0)
brakeman (4.0.1)
bugsnag (5.4.1)
builder (3.2.3)
@@ -477,6 +479,7 @@ DEPENDENCIES
base62-rb
bcrypt
benchmark-ips
+ bootsnap
brakeman
bugsnag
bundler-audit
diff --git a/config/boot.rb b/config/boot.rb
index 1e6be380a..d4e267b7e 100644
--- a/config/boot.rb
+++ b/config/boot.rb
@@ -2,6 +2,9 @@
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", __FILE__)
require "bundler/setup" if File.exists?(ENV["BUNDLE_GEMFILE"])
+# Do all the boot optimizations
+require 'bootsnap/setup'
+
# Must be a load so we can load again during reloads.
load File.expand_path("../dotenv.rb", __FILE__)
$ # After bootsnap
$ time DISABLE_SPRING=1 bin/rails r 'exit 0'
real 0m3.455s
user 0m2.444s
sys 0m0.872s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment