# Why does ruby load rails so slow?

**URL:** <https://www.ruby-forum.com/t/why-does-ruby-load-rails-so-slow/169027>\
**Category:** Ruby\
**Created:** [May 28, 2009, 3:51pm UTC](https://www.ruby-forum.com/t/why-does-ruby-load-rails-so-slow/169027 "2009-05-28T15:51:43Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![rogerdpack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@rogerdpack](https://www.ruby-forum.com/u/rogerdpack)\
**Post date:** [May 28, 2009, 3:51pm UTC](https://www.ruby-forum.com/t/why-does-ruby-load-rails-so-slow/169027/1 "2009-05-28T15:51:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rogerdpack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@rogerdpack](https://www.ruby-forum.com/u/rogerdpack)\
**Post date:** [May 28, 2009, 4:20pm UTC](https://www.ruby-forum.com/t/why-does-ruby-load-rails-so-slow/169027/2 "2009-05-28T16:20:59Z")

</div>

Roger P. [removed\_email\_address@domain.invalid](mailto: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.

---

<div class="post-metadata">

**Author:** ![rogerdpack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@rogerdpack](https://www.ruby-forum.com/u/rogerdpack)\
**Post date:** [May 28, 2009, 4:31pm UTC](https://www.ruby-forum.com/t/why-does-ruby-load-rails-so-slow/169027/3 "2009-05-28T16:31:02Z")

</div>

On Thu, May 28, 2009 at 9:52 AM, Roger P. [removed\_email\_address@domain.invalid](mailto: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

---

<div class="post-metadata">

**Author:** ![rogerdpack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@rogerdpack](https://www.ruby-forum.com/u/rogerdpack)\
**Post date:** [May 28, 2009, 6:50pm UTC](https://www.ruby-forum.com/t/why-does-ruby-load-rails-so-slow/169027/4 "2009-05-28T18:50:52Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![rogerdpack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@rogerdpack](https://www.ruby-forum.com/u/rogerdpack)\
**Post date:** [May 28, 2009, 5:58pm UTC](https://www.ruby-forum.com/t/why-does-ruby-load-rails-so-slow/169027/5 "2009-05-28T17:58:07Z")

</div>

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:

> **[GitHub - candlerb/snailgun: Preload and fork ruby interpreter for fast script...](https://github.com/candlerb/snailgun)**
>
> Preload and fork ruby interpreter for fast script startup - GitHub - candlerb/snailgun: Preload and fork ruby interpreter for fast script startup

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.

---

<div class="post-metadata">

**Author:** ![rogerdpack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@rogerdpack](https://www.ruby-forum.com/u/rogerdpack)\
**Post date:** [May 28, 2009, 8:22pm UTC](https://www.ruby-forum.com/t/why-does-ruby-load-rails-so-slow/169027/6 "2009-05-28T20:22:15Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![rogerdpack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@rogerdpack](https://www.ruby-forum.com/u/rogerdpack)\
**Post date:** [May 28, 2009, 9:31pm UTC](https://www.ruby-forum.com/t/why-does-ruby-load-rails-so-slow/169027/7 "2009-05-28T21:31:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rogerdpack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@rogerdpack](https://www.ruby-forum.com/u/rogerdpack)\
**Post date:** [May 28, 2009, 7:30pm UTC](https://www.ruby-forum.com/t/why-does-ruby-load-rails-so-slow/169027/8 "2009-05-28T19:30:10Z")

</div>

On May 28, 10:52 am, Roger P. [removed\_email\_address@domain.invalid](mailto: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.

---

<div class="post-metadata">

**Author:** ![rogerdpack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@rogerdpack](https://www.ruby-forum.com/u/rogerdpack)\
**Post date:** [May 28, 2009, 9:32pm UTC](https://www.ruby-forum.com/t/why-does-ruby-load-rails-so-slow/169027/9 "2009-05-28T21:32:51Z")

</div>

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)
