Feature #13602
closedOptimize instance variable access if $VERBOSE is not true when compiling
Description
This patch optimizes instance variable lookup in the case the $VERBOSE
is not true when compiling. If $VERBOSE is not true when compiling
code, it makes the instance variable access use an optimized VM
instruction that does not check $VERBOSE at runtime.
This does not change the behavior if $VERBOSE is not changed at runtime,
only when $VERBOSE is not true when compiling the code, but is true when
running it. In the case where $VERBOSE is not true when compiling and
true at runtime, this patch makes ruby no longer emit the warning
message.
Using a similar benchmark as #10396:
require 'benchmark/ips'
class A
def initialize
@c = @d = @e = @f = nil
end
def b
@c || @d || @e || @f
end
end
Benchmark.ips do |x|
x.report("A.new.b"){A.new.b}
x.report("A.allocate.b"){A.allocate.b}
end
Before Patch:
A.new.b 347.380k (_ 1.7%) i/s - 1.741M
A.allocate.b 862.884k (_ 0.4%) i/s - 4.317M
A.new.b 338.830k (_ 1.7%) i/s - 1.706M
A.allocate.b 848.036k (_ 0.4%) i/s - 4.254M
A.new.b 344.167k (_ 1.7%) i/s - 1.731M
A.allocate.b 826.183k (_ 0.4%) i/s - 4.138M
After Patch:
A.new.b 350.251k (_ 1.7%) i/s - 1.753M
A.allocate.b 900.666k (_ 0.7%) i/s - 4.512M
A.new.b 349.868k (_ 1.7%) i/s - 1.760M
A.allocate.b 898.292k (_ 0.4%) i/s - 4.505M
A.new.b 349.690k (_ 1.7%) i/s - 1.751M
A.allocate.b 888.524k (_ 0.6%) i/s - 4.444M
So about a 1-2% increase in the case where instance variables are
already initialized, and about 5-7% increase in the case where
instance variables are not initialized.
Files