From: Aaron Patterson Date: 2011-07-06T06:56:09+09:00 Subject: [ruby-core:37813] Re: [Ruby 1.9 - Bug #4962][Open] come back gem_prelude! --7JfCtLOvnd9MIVvH Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Jul 02, 2011 at 02:18:35PM +0900, Yusuke Endoh wrote: >=20 > Issue #4962 has been reported by Yusuke Endoh. >=20 > ---------------------------------------- > Bug #4962: come back gem_prelude! > http://redmine.ruby-lang.org/issues/4962 >=20 > Author: Yusuke Endoh > Status: Open > Priority: Normal > Assignee: Eric Hodel > Category: lib > Target version: 1.9.3 > ruby -v: ruby 1.9.3dev (2011-07-01 trunk 32356) [i686-linux] >=20 >=20 > Hello, rubygems developers >=20 > Kosaki-san noticed that 1.9.3 is slower than 1.9.2 on many benchmarks. > http://www.atdot.net/sp/view/5qunnl >=20 > I investigated and found that the cause is the lack of gem_prelude.rb. >=20 > Loading rubygems seems to create many objects and keep the references > to them. See below: >=20 >=20 > $ ruby -ve 'GC.start; p ObjectSpace.count_objects[:TOTAL]' > ruby 1.9.2p180 (2011-02-18 revision 30909) [i686-linux] > 9821 >=20 > $ ./ruby -ve 'GC.start; p ObjectSpace.count_objects[:TOTAL]' > ruby 1.9.3dev (2011-07-01 trunk 32356) [i686-linux] > 19638 >=20 > $ ./ruby --disable-gems -ve 'GC.start; p ObjectSpace.count_objects[:TOTAL= ]' > ruby 1.9.3dev (2011-07-01 trunk 32356) [i686-linux] > 9821 >=20 >=20 > The number of live objects is proportional to the cost of GC mark phase. > You can actually confirm the performance degradation with the following > benchmark script: >=20 > require 'tempfile' > max =3D 200_000 > str =3D "Hello world! " * 1000 > f =3D Tempfile.new('yarv-benchmark') > f.write str > GC::Profiler.enable > max.times{ > f.seek 0 > f.read > } > p GC::Profiler.total_time >=20 >=20 > $ time ruby -v bm_io_file_read.rb > ruby 1.9.2p180 (2011-02-18 revision 30909) [i686-linux] > 0.7280460000000308 >=20 > real 0m3.965s > user 0m2.940s > sys 0m1.024s >=20 > $ time ./ruby -v bm_io_file_read.rb > ruby 1.9.3dev (2011-07-01 trunk 32356) [i686-linux] > 1.396088000000029 >=20 > real 0m4.786s > user 0m3.716s > sys 0m1.060s >=20 > $ time ./ruby --disable-gems -v bm_io_file_read.rb > ruby 1.9.3dev (2011-07-01 trunk 32356) [i686-linux] > 0.7640390000000309 >=20 > real 0m4.079s > user 0m2.872s > sys 0m1.192s >=20 >=20 > The performance degradation can be seen by not only such micro benckmarks, > but also my puzzle solvers :-( >=20 >=20 > There are some approaches to address the problem: >=20 > 1. to introduce a generational GC; this is impossible until 2.0 because > it requires modifications to all extension libraries. >=20 > 2. to diet rubygems; do not create any string, array, hash, and any > object as much as possible, and do not keep the references to them. >=20 > 3. to restore gem_prelude.rb to delay loading rubygems. We can also help rbconfig go on a diet. I know it's not enough, but this eliminated ~400 object allocations on my machine. (what is the MAKEFILE_CONFIG for anyway?) diff --git a/tool/mkconfig.rb b/tool/mkconfig.rb index a2221f0..d78a347 100755 --- a/tool/mkconfig.rb +++ b/tool/mkconfig.rb @@ -202,8 +202,6 @@ print <