Speeding up Slow Spork Startup for Rails 2.3+

If you noticed spork startup getting slower when switching to Rails 2.3, your not alone 😉

  • Views are eager loaded
  • app/ is eager loaded (when config.cache_classes is on)

Without hack: 18s startup
With hack: 2s startup 😀

Try it

require 'spork/app_framework/rails'
Spork::AppFramework::Rails::NinjaPatcher.class_eval do
  # views are preloaded  spork must be restarted for view changes
  def delay_eager_view_loading
    puts "removed because i am too slow..."

  # do not preload application files
  # alternatively urn off config.cache_classes
  def delay_app_preload
    ::Rails::Initializer.send(:define_method, :load_application_classes){}

Spork.prefork do

6 thoughts on “Speeding up Slow Spork Startup for Rails 2.3+

  1. Hello

    That delay_app_preload method fixed cucumber preloading issue when cache_classes = true..

    However, that delay view logic has view can’t be reloaded problem..

    thx for sharing

  2. Hello there! After more than 3 years, we still use Rails 2.3, and I was trying to use this nice trick but…the

    require ‘spork/app_framework/rails’

    line is making spork upset…

    no such file to load — spork/app_framework/rails (LoadError)

    so I tried to remove it. It works, but I don’t see any changes in the speed. It’s still around 10 seconds loading…any clue about this?

    Many thanks!

  3. Updated the code, to explode when the class is not there,
    my guess would be that either the module is no longer there or the methods got renamed, check out an older version of spork, or dig through the spork repo to find what it is called nowadays

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 )

Facebook photo

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

Connecting to %s