Development checks for fast boottime

A few simple checks to make sure we are not regressing into slow boot times by preloading to many things. Needs to be the last initializer so it catches what all the others are doing -> zz.rb

Code

# config/initializers/zz.rb
if Rails.env.development?
  # make sure we do not regress into slow startup time by preloading to much
  Rails.configuration.after_initialize do
    [
      ActiveRecord::Base.send(:descendants).map(&:name),
      ActionController::Base.descendants.map(&:name),
      (File.basename($0) != "rake" && defined?(Rake) && "rake"),
    ].compact.flatten.each { |c| raise "#{c} should not be loaded" }
  end
end

Result

config/initializers/zz.rb:9:in `block (2 levels) in ': 
User should not be loaded (RuntimeError)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s