From: Kirk Haines Date: 2011-01-28T23:59:09+09:00 Subject: Re: performance question On Thu, Jan 27, 2011 at 1:10 PM, klochner wrote: > Ignoring the between-test comparisons, there is clearly a slowdown > after loading rails.  My *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' => true irb(main):002:0> junk = [] => [] 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) => 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) => true irb(main):005:0> 10000.times {|n| junk << n.to_s} => 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) => true irb(main):007:0> 20000.times {|n| junk << n.to_s} => 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) => true irb(main):009:0> 40000.times {|n| junk << n.to_s} => 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) => true irb(main):011:0> 1000000.times {|n| junk << n.to_s} => 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) => true Kirk Haines Developer Engine Yard