20

I just got my rails 2.3.8 app running on ruby 1.9.1. To get into the console, start the webserver, anything that initializes rails, takes 3 - 4 times longer in ruby 1.9 than in ruby 1.8.7. I'm using ruby version managers so I can easily switch between ruby 1.9 and ruby 1.8.7. The speed difference happens in both production and development. I want to use 1.9 because its must faster once everything is running, but the startup time is so bad the app is timing out on Heroku on the first request.

Any ideas why ruby 1.9 would be 3 - 4 times slower? I can't figure it out for the life of me.

kiamlaluno
  • 24,790
  • 16
  • 70
  • 85
Ben Johnson
  • 201
  • 2
  • 3
  • Or figure out where its spending its time. – Ben Johnson May 26 '10 at 14:52
  • I have confirmed this issue exists with a fresh rails app. So it is definitely not a gem or something application specific. – Ben Johnson May 26 '10 at 16:34
  • When you say 3 - 4 times slower, how long is it taking in seconds? If ruby1.9 takes 3 seconds to ruby1.8's 1 second, you're likely having different issues than if ruby1.9 takes 60 seconds and ruby1.8 takes 20 seconds! – nfm Jun 03 '10 at 10:22
  • I've noticed a delay of ~2 seconds on the first request to my own app, too, but I don't think that would cause timeouts. It **might** (that's a very tentative "might") have something to do with 'autoload' versus 'require' in the Rails library. 'autoload' will only load the given file when an associated constant is accessed, so it's basically lazy loading. If a lot of lazy loading is going on, that **could** be doing something. This could only really be the issue if it's just the _first_ request that takes a long time. Otherwise just go ahead and ignore me. – Twisol Jun 05 '10 at 08:23
  • Does this happen also locally? – Shyam Jun 08 '10 at 14:36
  • After switching to rails3/ruby19 the average rails env loading time is about 30 secs compared to the 5 secs it took on rails2/ruby18. I'm trying just now to use 1.9.2-head to see if there's any improvement. – knoopx Dec 10 '10 at 11:39

2 Answers2

6

Try using 1.9.2-head instead of 1.9.1. It is the recommended version for Rails 3, so you may have better luck. Rails 2.3.8 starts up very quick on 1.9.2-head from the tests I just ran locally (with Authlogic installed too, btw).

If you are using RVM, type the following:

rvm install 1.9.2-head
rvm use 1.9.2-head

Edit: I tried 1.9.1 p378 with the same app and the start up time took about 13 seconds compared to 5 seconds on 1.9.2-head. 1.9.2-rc1 is due out this month I believe, so that's good news :)

Awgy
  • 1,082
  • 11
  • 14
0

It's probably because ruby 1.9 uses gem_prelude (which gives you a large load path) instead of normal rubygems. Checkout the length of $: -- that gets searched once for each require, causing extra time

If you want it the old way, (upgrade to the latest version of rubygems and) run ruby --disable-gems

If you are on windows, take a look into my faster_require gem.

http://github.com/rdp/faster_require

Though I suppose, now that you mention it, it might help in 1.9 Linux. Maybe.

GL! -rp

rogerdpack
  • 50,731
  • 31
  • 212
  • 332