Forum: Ruby OSX: require seems very 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.
Matt W. (Guest)
on 2008-10-29 14:51
Hi,

I'm working on a large rails app on my MacBook Pro (2.16 GHz Intel Core
Duo / 2GB RAM). OS X is 10.5.5.

On my machine, it takes about 30 seconds to load the rails environment
for our project. For my colleagues, who are mostly using Ubuntu, it's
much faster.

I've done some basic profiling and it looks as though the time is being
spent simply requiring files.

I made a very simple script and got my colleagues to run it:

    t = Time.now]
    require 'rubygems'
    require 'activesupport'
    puts Time.now - s

They're mostly getting sub-second performance, while on my machine it
takes over 3 seconds, just to load ActiveSupport.

Can anyone explain what is going on, and better, how to speed this up
for me? Or should I just live with this? Is this comparable to other
people's experience on a Mac?

FYI, ruby -v says
ruby 1.8.6 (2007-09-24 patchlevel 111) [i686-darwin9.5.0]

This is after I built ruby from source to try and resolve this,
following[1]. It has made little difference, in fact if anything things
seem to be even slower since I switched my path to use /usr/local/bin
rather than the one installed with Leopard.

Thanks in advance,
Matt

[1]http://hivelogic.com/articles/2008/02/ruby-rails-leopard
Thomas S. (Guest)
on 2008-10-29 18:20
(Received via mailing list)
On Oct 29, 8:51 am, Matt W. <removed_email_address@domain.invalid> wrote:
> spent simply requiring files.
>
> I made a very simple script and got my colleagues to run it:
>
>     t = Time.now]
>     require 'rubygems'
>     require 'activesupport'
>     puts Time.now - s
>
> They're mostly getting sub-second performance, while on my machine it
> takes over 3 seconds, just to load ActiveSupport.

ActiveSupport is pretty big and goes about things in a very round
about way. So it is a slow to load regardless. However, 3 seconds does
seem overly slow.

Some comparison could help evaluate the problem. Try installing facets
(gem install facets) and time how long it take to require 'facets'.
That's another big library, but simpler in design. If that take more
than a second than something is seriously wrong.

T.
Matt W. (Guest)
on 2008-10-29 19:03
Thomas S. wrote:
> ActiveSupport is pretty big and goes about things in a very round
> about way. So it is a slow to load regardless. However, 3 seconds does
> seem overly slow.

So, an update: I discovered this thread[1] and this one[2] and tried
rebuilding ruby with -O3 and --disable-pthreads, and things have got a
bit better.

My benchmark test now takes about 1.2 seconds.

However the benchmark from [2] takes about 44 seconds, which is
appalling in comparison to the scores from similar machines on that
thread.

I have very little idea what I'm going when building things from source,
but I feel as if I'm on to something here. Any pointers appreciated very
much.

> Some comparison could help evaluate the problem. Try installing facets
> (gem install facets) and time how long it take to require 'facets'.
> That's another big library, but simpler in design. If that take more
> than a second than something is seriously wrong.

Nope, that's comparatively really quick, like 0.3 secs max.

[1]http://www.ruby-forum.com/topic/162774
[2]http://www.ruby-forum.com/topic/125344
Robert K. (Guest)
on 2008-10-30 12:08
(Received via mailing list)
2008/10/29 Matt W. <removed_email_address@domain.invalid>:

> I have very little idea what I'm going when building things from source,
> but I feel as if I'm on to something here. Any pointers appreciated very
> much.

Maybe you have an extremely lenghty library path or directories reside
on slow disks (e.g. NFS on a different machine, potentially with
network trouble).  You can check the path with

ruby -e 'puts $:'

Kind regards

robert
This topic is locked and can not be replied to.