3

Similar issue to Slow loading rails environment

Loading the rails environment takes quite a bit of time and I'm not sure exactly why.

time ruby -r./config/environment.rb -e ""
 real   0m18.590s
 user   0m17.200s
 sys    0m1.320s

Are there any tools/ways that can help me find why it is spending so much time to load the environment?

The project is fairly large, so I am assuming that it is coming from all the gem dependencies, but I would think that it would be able to be improved somehow.

Community
  • 1
  • 1
Kyle d'Oliveira
  • 6,382
  • 1
  • 27
  • 33

2 Answers2

4

If you are using Ruby 1.9 then see this blog post it may be the issue you are experiencing. If it is it has to do with the amount of requires in your project and the way that method is implemented in 1.9. There is a patch available to improve this performance.

Paul.s
  • 38,494
  • 5
  • 70
  • 88
  • I think this is the most likely cause of the problem. The patch supplied on the blog didn't work for me, but I now have a base line to try to get something similar working for me. – Kyle d'Oliveira Jul 11 '11 at 17:36
0

I tried patching my ruby with the rhnh patch cited above as well as the rvm-patchsets (on independent ruby installs of course) but didn't pick up a lot of performance. But some do it seems so maybe it's a ruby version or lower level issue.

My current workaround, at least in my dev environment, is to use rails-sh to preload the environment one time and then reuse it in your rails/rake commands. It's a big performance pickup. Wrote more details on it in this answer.

Community
  • 1
  • 1
yuvilio
  • 3,795
  • 32
  • 35