Skip to content

Instantly share code, notes, and snippets.

@anildigital
Forked from josevalim/application.rb
Created December 6, 2011 13:37
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 anildigital/1438232 to your computer and use it in GitHub Desktop.
Save anildigital/1438232 to your computer and use it in GitHub Desktop.
Potentially faster boot
# Please add the following lines after Bundler.require
# and before "class Application < Rails::Application"
# in your config/application.rb
#
# Notice this is just an experiment, don't leave those
# lines there after the experiment. Then please benchmark
# your app boot time in development before and after adding
# those lines. A simple benchmark is:
#
# time script/rails runner "MODEL"
#
# Where MODEL is a model available in your app. Also,
# please run the command above at least three times to
# ensure we don't have fake samples. :)
#
# Please post the results in the comments below of the
# benchmarks before and after adding the code. <3
#
# This patch should work on Rails 3.0, 3.1 and master.
#
# Extra: if you could run your app in development and
# production (in your machine!!) with this patch on
# for a couple minutes and report any errors, you will
# win extra <3 <3 <3.
require "active_support/dependencies"
ActiveSupport::Dependencies::WatchStack.class_eval do
def watching?
!@watching.empty?
end
end
def load_dependency(file)
if ActiveSupport::Dependencies.load? && ActiveSupport::Dependencies.constant_watch_stack.watching?
ActiveSupport::Dependencies.new_constants_in(Object) { yield }
else
yield
end
rescue Exception => exception # errors from loading file
exception.blame_file! file
raise
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment