views:

657

answers:

2

I've got a ruby script which takes about 30 seconds to startup. It takes that much because it tries to load all libraries and stuff.

When I do "ruby.exe -v" it's instant.

I don't want to touch the original ruby script, which is not written by me.

What are the tricks to speed this process up?

  • Can I precompile it?
  • Can I precache all of these files?

I need to do this under Windows or Cygwin.

UPDATE :

  • Scripts is quite slow in Linux/Mac as well, this condition is not specific to Windows.
  • This is normal ruby 1.8.7 (similar speed in other ruby versions)
  • Main bottleneck is loading so many libraries (I removed unrequired files and libraries and decrease the time to drastically but still slow)
A: 

Sorry, but there is no way to compile a ruby script. What sort of stuff is this script loading/doing?

You're right, 30 seconds is quite long. Is this script making calls out to the web or databases that are very expensive? It's hard to believe that libraries would take so long to load

... I just noticed the comments and saw that you got it down to 1-4 seconds...that's very good, especially when coming down from 30. Other comments are right, please post the requires at the top of the script

efalcao
+1  A: 

I presume the script uses rubygems? (It'll say require "rubygems" if so)

You could try installing minigems (gem install minigems) and then use minigems instead of rubygems - should speed things up a little.

Paul Hedderly