Forum: Ruby why does ruby load rails so slow?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Roger P. (Guest)
on 2009-05-28 17:51
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
Pascal J. Bourguignon (Guest)
on 2009-05-28 18:20
(Received via mailing list)
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.
Gregory B. (Guest)
on 2009-05-28 18:31
(Received via mailing list)
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
Brian C. (Guest)
on 2009-05-28 19:58
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.
Roger P. (Guest)
on 2009-05-28 20:50
> 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 :)

-=r
Luis L. (Guest)
on 2009-05-28 21:30
(Received via mailing list)
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.
Roger P. (Guest)
on 2009-05-28 22:22
> 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 :)

-=r
Charles Oliver N. (Guest)
on 2009-05-28 23:31
(Received via mailing list)
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
Brian C. (Guest)
on 2009-05-28 23:32
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 :)

It's mainly because there there's so darn much of it (try 'puts
$LOADED_FEATURES' from within script/console)
This topic is locked and can not be replied to.