From 1ae67a21f53e8d3237c7eafb0f4888bcca6f4f4a Mon Sep 17 00:00:00 2001 From: Sam Saffron Date: Tue, 25 Apr 2017 10:15:12 -0700 Subject: [PATCH] FEATURE: add support for bootsnap in dev To use bootsnap which speeds up rails boot add BOOTSNAP=1 to your env --- Gemfile | 1 + Gemfile.lock | 7 ++++++- config/boot.rb | 13 +++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index fa8554c1550..6bf55b31d8e 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,7 @@ source 'https://rubygems.org' # if there is a super emergency and rubygems is playing up, try #source 'http://production.cf.rubygems.org' +gem 'bootsnap', require: false def rails_master? ENV["RAILS_MASTER"] == '1' diff --git a/Gemfile.lock b/Gemfile.lock index 3ccbe4a87dd..5bd3fd8b3c8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -62,6 +62,9 @@ GEM rack (>= 0.9.0) binding_of_caller (0.7.2) debug_inspector (>= 0.0.1) + bootsnap (0.2.10) + msgpack (~> 1.0) + snappy (~> 0.0.15) builder (3.2.3) bullet (5.4.2) activesupport (>= 3.0.0) @@ -166,7 +169,7 @@ GEM metaclass (~> 0.0.1) mock_redis (0.15.4) moneta (1.0.0) - msgpack (1.0.2) + msgpack (1.1.0) multi_json (1.12.1) multi_xml (0.6.0) multipart-post (2.0.0) @@ -354,6 +357,7 @@ GEM rack-protection (~> 1.4) tilt (>= 1.3, < 3) slop (3.6.0) + snappy (0.0.15) spork (1.0.0rc4) spork-rails (4.0.0) rails (>= 3.0.0, < 5) @@ -400,6 +404,7 @@ DEPENDENCIES barber better_errors binding_of_caller + bootsnap bullet byebug certified diff --git a/config/boot.rb b/config/boot.rb index afa16ad5afd..5c5ccd4efc3 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -9,3 +9,16 @@ require 'rubygems' ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) + +if ENV['BOOTSNAP'] #&& ENV['RAILS_ENV'] != 'production' + require 'bootsnap' + Bootsnap.setup( + cache_dir: 'tmp/cache', # Path to your cache + development_mode: ENV['BOOTSNAP_DEV'] == 'development', + load_path_cache: true, # Should we optimize the LOAD_PATH with a cache? + autoload_paths_cache: true, # Should we optimize ActiveSupport autoloads with cache? + disable_trace: false, # Sets `RubyVM::InstructionSequence.compile_option = { trace_instruction: false }` + compile_cache_iseq: true, # Should compile Ruby code into ISeq cache? + compile_cache_yaml: true # Should compile YAML into a cache? + ) +end