On Thu, Jan 27, 2011 at 1:10 PM, klochner <klochner / gmail.com> wrote:

> Ignoring the between-test comparisons, there is clearly a slowdown
> after loading rails. =A0My *guess* is that it has to do with the size of
> ObjectSpace causing a slowdown in function lookup, but again, I was
> hoping someone here would have a more concrete understanding.

Garbage collection.

REE has some optimizations to how it manages GC, but the fundamentals
are still the same for any 1.8.x.  When a garbage collection cycle
starts, everything else stops. While it is running Ruby has to walk
through it's heaps, examining everything that looks like an object
that it can find.

The more stuff that is in there, the longer this takes. If there is a
lot of stuff in there, the impact can be significant.

You can readily see this yourself within an irb session.

irb(main):001:0> require 'benchmark'
=3D> true
irb(main):002:0> junk =3D []
=3D> []
irb(main):003:0> Benchmark.bm {|bm| bm.report {1000.times {GC.start}}}
      user     system      total        real
  0.780000   0.000000   0.780000 (  0.977218)
=3D> true
irb(main):004:0> Benchmark.bm {|bm| bm.report {1000.times {GC.start}}}
      user     system      total        real
  0.780000   0.000000   0.780000 (  0.796975)
=3D> true
irb(main):005:0> 10000.times {|n| junk << n.to_s}
=3D> 10000
irb(main):006:0> Benchmark.bm {|bm| bm.report {1000.times {GC.start}}}
      user     system      total        real
  1.120000   0.000000   1.120000 (  1.266903)
=3D> true
irb(main):007:0> 20000.times {|n| junk << n.to_s}
=3D> 20000
irb(main):008:0> Benchmark.bm {|bm| bm.report {1000.times {GC.start}}}
      user     system      total        real
  1.900000   0.020000   1.920000 (  2.125608)
=3D> true
irb(main):009:0> 40000.times {|n| junk << n.to_s}
=3D> 40000
irb(main):010:0> Benchmark.bm {|bm| bm.report {1000.times {GC.start}}}
      user     system      total        real
  2.360000   0.010000   2.370000 (  2.441193)
=3D> true
irb(main):011:0> 1000000.times {|n| junk << n.to_s}
=3D> 1000000
irb(main):012:0> Benchmark.bm {|bm| bm.report {1000.times {GC.start}}}
      user     system      total        real
 32.970000   0.250000  33.220000 ( 36.181590)
=3D> true


Kirk Haines
Developer
Engine Yard