On Wed, Jul 09, 2008 at 12:13:35PM +0900, SASADA Koichi wrote:
> Please give me comments.
> 
> A compiler of Ruby 1.9 compile ruby script, without "trace
> instruction" by default.  This means that some "trace event" used by
> set_trace_func() is not active (line, call, leave).  "trace
> instruction" invoke some hook procs.
> 
> This is a reasone of this issue:
> http://redmine.ruby-lang.org/issues/show/161
> 
> lib/profile.rb enable to add trace insn.  You need to require
> lib/profile.rb *before* target programs are compiled.  require *in*
> target program is not affect profiling because target programs are
> already compiled.  If you run ruby with profiler specified in
> command line, you have correct result:
> 
> > ./ruby -v -rprofile ../trunk/test.rb
> > ruby 1.9.0 (2008-07-08 revision 0) [i686-linux]
> >   %   cumulative   self              self     total
> >  time   seconds   seconds    calls  ms/call  ms/call  name
> >  67.44     0.29      0.29     2432     0.12     4.84  Object#ackerman
> >  20.93     0.38      0.09     3676     0.02     0.02  Fixnum#==
> >   6.98     0.41      0.03     1188     0.03     0.03  Fixnum#+
> >   4.65     0.43      0.02     2431     0.01     0.01  Fixnum#-
> >   0.00     0.43      0.00        1     0.00     0.00  Module#method_added
> >   0.00     0.43      0.00        1     0.00     0.00  Kernel.require
> >   0.00     0.43      0.00       57     0.00     0.00  Fixnum#>
> >   0.00     0.43      0.00        1     0.00     0.00  RubyVM::FrozenCore.core_define_method
> >   0.00     0.43      0.00        2     0.00     0.00  IO#set_encoding
> >   0.00     0.43      0.00        1     0.00   430.00  #toplevel
> 
> The reason why I eliminate "trace instruction" is performance.  In
> most cases, we don't need "trace instruction".  If there is no
> hooks, "trace instruction" means "nop instruction", waste some
> performance.
> 
> This is a benchmark result:
> http://www.atdot.net/sp/readonly/30xp3k
> ruby 1.9.0 (2008-07-09 revision 17965) [x86_64-linux]
> 
> "wo-trace" is current 1.9, compile without trace instruction.
> another one "ruby 1.9.0 (2008-07-09 revision 17965) [x86_64-linux]"
> is modified version which include trace instruction everytime.
> 
> "wo-trace" is fast as a few percent.
> 
> 
> But there are some drawback:
> - spec changing from 1.8
> - difficult to describe especially for newbe
>  (or 1.8 users except ruby-core readers?)
> - dave should re-write his book :)
> 
> There are some technical solutions.  One is to insert one-byte trace
> instruction ([ruby-core:17653]) dynamically.  But I think we can't
> support it in high-quality by 1.9.1 release.
> 
> 
> I consier this issue and current my solutions are:
> 
> - enable (include) trace insn on 1.9.1 everytime
> - speed up with one-byte trace instruction on 1.9.x (x > 1)
> - you can disable to compile with trace insn by require some
>   library (ruby -r without-trace-insn ...) on 1.9.1
>   in concrete term, modify
>   RubyVM::InstructionSequence.compile_option.
> - you can write about it on performance tips page :)
> 
> 
> Any comments?
> -- 
> // SASADA Koichi at atdot dot net
> 
How about compile with trace insn and let VM make two versions with and without trace insn.
--