Why does ruby load rails so slow?


#1

Question. Currently with rails startup time in linux for me is like 6s,
in windows like…20s, but regardless, anybody know just why this is
taking so long (I’m pretty sure it’s cpu bound–curious if anyone’s
investigated this).
Anyone know any tricks to load things quicker?
Thanks much.
-=r


#2

Roger P. removed_email_address@domain.invalid writes:

Question. Currently with rails startup time in linux for me is like 6s,
in windows like…20s, but regardless, anybody know just why this is
taking so long (I’m pretty sure it’s cpu bound–curious if anyone’s
investigated this).
Anyone know any tricks to load things quicker?

There are two tricks:

  • compile each source file into a “binary” fast loading file, and then
    load them.

  • load everything, then save the memory image. Next time, boot ruby
    with that saved memory image, instead of an empty one.

There’s also a third option:

  • compile the program to a native executable.

Ooops! These options are not available to Matzacred Lisp, only in
implementations of Common Lisp, Scheme, Smalltalk, etc.

Well, theorically there’s nothing that would prevent you to implement
either option in Ruby, but the fact that it’s written in C instead of
Ruby. If it was written in Ruby, as a Ruby programmer you could do
something about it. Otherwise you’ll have to find a C programmer and
motivate him to work on it…

There’s already a Ruby parser written in Ruby, perhaps it would be
time to implement a Ruby compiler in Ruby.


#3

On Thu, May 28, 2009 at 9:52 AM, Roger P. removed_email_address@domain.invalid
wrote:

Question. Currently with rails startup time in linux for me is like 6s,
in windows like…20s, but regardless, anybody know just why this is
taking so long (I’m pretty sure it’s cpu bound–curious if anyone’s
investigated this).
Anyone know any tricks to load things quicker?

Probably a better question for the Rails list. But…

Are you talking about a bare rails app, or something with a bunch of
plugins and gems being loaded?
You should look at what your plugins are doing, they may churn heavily
at startup if they’re loading lots of things.

-greg


#4

I find it speeds things up hugely on my old Thinkpad X30 laptop.

Man I wish I’d had that back when I was using my old macbook PPC :slight_smile:

-=r


#5

Roger P. wrote:

Question. Currently with rails startup time in linux for me is like 6s,
in windows like…20s, but regardless, anybody know just why this is
taking so long (I’m pretty sure it’s cpu bound–curious if anyone’s
investigated this).
Anyone know any tricks to load things quicker?

You could try this, which I knocked together last week:
http://github.com/candlerb/snailgun

It’s for Linux only. Basically, it starts a Ruby interpreter and loads
in all the libraries demanded by your application (gems and all, if
they’re declared in config/environment.rb). Then each time you want a
new Rails process, you can just fork the preloaded one, using a slightly
different command to normal:

frake # run tests
fautotest # background testing
fconsole # interactive console
fruby script/server # web server

I find it speeds things up hugely on my old Thinkpad X30 laptop.

Regards,

Brian.


#6

I did ran some test between bare C doing IO with lot of files and
folders and compare it with ruby. There are so many functions called
just to reach the native API that make things slow.

Don’t have to much time now to invest on fixing this, sorry.

Oh I wasn’t complaining about the speed on windows (though it is
slower). I was mostly wondering about ruby itself being so slow to load
rails :slight_smile:

-=r


#7

Roger P. wrote:

Question. Currently with rails startup time in linux for me is like 6s,
in windows like…20s, but regardless, anybody know just why this is
taking so long (I’m pretty sure it’s cpu bound–curious if anyone’s
investigated this).
Anyone know any tricks to load things quicker?
Thanks much.

One reason I found was that things like script/console actually start
rails twice…once to boot the console script, and then another time
to spin up a new Ruby process running IRB.

I filed a bug on it against Rails, but I don’t think it’s been accepted
yet.

  • Charlie

#8

On May 28, 10:52 am, Roger P. removed_email_address@domain.invalid wrote:

Question. Currently with rails startup time in linux for me is like 6s,
in windows like…20s, but regardless, anybody know just why this is
taking so long (I’m pretty sure it’s cpu bound–curious if anyone’s
investigated this).
Anyone know any tricks to load things quicker?
Thanks much.

There is a huge IO problem with Ruby on how deal with Windows API IO
stuff.

I did ran some test between bare C doing IO with lot of files and
folders and compare it with ruby. There are so many functions called
just to reach the native API that make things slow.

Don’t have to much time now to invest on fixing this, sorry.


#9

Roger P. wrote:

I did ran some test between bare C doing IO with lot of files and
folders and compare it with ruby. There are so many functions called
just to reach the native API that make things slow.

Don’t have to much time now to invest on fixing this, sorry.

Oh I wasn’t complaining about the speed on windows (though it is
slower). I was mostly wondering about ruby itself being so slow to load
rails :slight_smile:

It’s mainly because there there’s so darn much of it (try ‘puts
$LOADED_FEATURES’ from within script/console)