Speeding up Rails startup time
rhnh.net
rhnh.net
* Wow, an O(n^2) require algo. I guess this really drives home that we shouldn't make basic assumptions about the quality of the libs we use without actually looking at them. Great catch.
* For all of you waiting for this to be pulled into Ruby master. Why not just patch your copy in the meantime?
I've patched my local copy. Feels like I have doubled my computer speed! Seriously though, I can't believe the fix was so easy, and the ruby core hasn't done something about this yet.
The last major external fix to ruby was with the REE people, and that still hasn't made it back into MRI. So I'm a bit worried this patch will get rejected and the problem won't be fixed.
See http://www.youtube.com/watch?v=kWOAHIpmLAI&t=34m9s for a recent talk on it by @tenderlove.
I'm back to shit rails bootup speeds for now. But at least I now have hope that it's possible that a fix may be on the horizon.
joevandyk posted a great example project here: https://github.com/joevandyk/slow-rails
20second bootup of an empty project = hair on fire omgwtf issue. the start of phpenvy? (no, not really)
You could probably also do this by running a Rails instance as a service, and then every time you want to run Rails, you tell the service to fork, and use the forked thread. I think this is how Passenger works actually?
FWIW, this is how Spork works, a tool people have been using a lot more recently in order to have fast(er) tests on Rails 3. Spork boots up an environment then waits for RSpec (or whatever) to hit it over DRb and then it forks off for that run.
Another full circle back to Lisp. Dumping a Lisp image file is much like you describe. (Just sayin'.)
One day in the early days of computing, General Electric had a problem with their computer. All of their engineers took a look at the problem. Although each was wise, they were unable to understand the complexity of the machinery and repair the error. A call was made to the retired engineer who had helped in the original set up of the machine.
The retired engineer walked around the machine for a few minutes, just looking it over, not touching anything. After a few minutes, He took out a piece of chalk, walked over and placed a large X on one particular part of the machine. He then said' "Tap it here with a hammer, just once."
After the one tap, the computer roared back to life and began working!
A few days later, GE received an invoice from the retired engineer for $10,000! This was a lot of money in those days, so they returned it to the engineer and asked that he itemize his invoice.
A few days later, they received an itemized bill which read:
Chalk for one X mark - $1.00
Knowing where to place the X - $9,999.00
This patch certainly improved my load time tremendously, but the core of the problem still lies with the way rubygems and bundler dump all directories of gems in the load path. The promise of $LOAD_PATH is that all the directories in it will be tried -- the most bang-for-buck optimization is thus minimizing its size.
If rubygems did this, everything would be much better.
There is one problem though, and it is that some libs are bad citizens and install stuff outside of lib|bin and depend on it (haml's VERSION file is an example of this), and that sucks.
rpg has a 'shitlist' with fixes for specific cases: https://github.com/rtomayko/rpg/blob/master/rpg-shit-list.sh...
My app which includes thinking-sphinx (which has a require '0.9.9'), breaks with it.
I used rails in a few projects, and performance was so painful even on pretty good hardware that I said never again. Go on the other hand is pure pleasure.