From: sam.rawlins@... Date: 2014-04-06T06:08:35+00:00 Subject: [ruby-core:61878] [ruby-trunk - Bug #9703] Inconsistent profile output Issue #9703 has been updated by Sam Rawlins. This is due to `profile.rb`'s `:specialized_instruction => false` compile option, on [line 5](https://github.com/ruby/ruby/blob/trunk/lib/profile.rb#L5). If you comment it out, none of the three cases will show any calls to `#==`. Specialized instructions are performance-optimized during compile-time. By default, specialized instructions are enabled. In the second example, `0==1` is _parsed_ before `require "profile"` is _evaluated_, so that `#==` is optimized, and not traced. The opposite is true in the first and third examples. You can also see how `0 == 1` is compiled differently w/ or w/o specialized instructions by comparing: puts RubyVM::InstructionSequence.compile("0 == 1", "foo.rb", "/foo.rb", 1).disasm with puts RubyVM::InstructionSequence.compile("0 == 1", "foo.rb", "/foo.rb", 1, specialized_instruction: false).disasm If this is not a bug, I think it should be documented, either in Profile, TracePoint, or InstructionSequence. I don't think there is one canonical list of specialized instructions, but a good place to start is [iseq_specialized_instruction()](https://github.com/ruby/ruby/blob/trunk/compile.c#L1924) and iseq_compile_each()'s [case NODE_MATCH](https://github.com/ruby/ruby/blob/trunk/compile.c#L4770). ---------------------------------------- Bug #9703: Inconsistent profile output https://bugs.ruby-lang.org/issues/9703#change-46090 * Author: Max Anselm * Status: Open * Priority: Normal * Assignee: * Category: lib * Target version: current: 2.2.0 * ruby -v: ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-linux] * Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN ---------------------------------------- The output of the profile lib seems to be partially dependent on how it is required. For example, ~~~ ruby -rprofile -e '0==1' ~~~ shows one call to Fixnum#== as expected ~~~ ruby -e 'require "profile"; 0==1' ~~~ does not show any calls to Fixnum#== !!! ~~~ ruby -e 'require "profile"; eval("0==1")' ~~~ again shows one call to Fixnum#== as expected. See also: http://stackoverflow.com/questions/22861559/what-is-the-difference-between-r-profile-and-require-profile -- https://bugs.ruby-lang.org/