1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/benchmark/attr_accessor.yml
Jeremy Evans 2d98593bf5 Support tracing of attr_reader and attr_writer
In vm_call_method_each_type, check for c_call and c_return events before
dispatching to vm_call_ivar and vm_call_attrset.  With this approach, the
call cache will still dispatch directly to those functions, so this
change will only decrease performance for the first (uncached) call, and
even then, the performance decrease is very minimal.

This approach requires that we clear the call caches when tracing is
enabled or disabled.  The approach currently switches all vm_call_ivar
and vm_call_attrset call caches to vm_call_general any time tracing is
enabled or disabled. So it could theoretically result in a slowdown for
code that constantly enables or disables tracing.

This approach does not handle targeted tracepoints, but from my testing,
c_call and c_return events are not supported for targeted tracepoints,
so that shouldn't matter.

This includes a benchmark showing the performance decrease is minimal
if detectable at all.

Fixes [Bug #16383]
Fixes [Bug #10470]

Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
2021-08-29 07:23:39 -07:00

29 lines
504 B
YAML

prelude: |
class C
attr_accessor :x
def initialize
@x = nil
end
class_eval <<-END
def ar
#{'x;'*256}
end
def aw
#{'self.x = nil;'*256}
end
def arm
m = method(:x)
#{'m.call;'*256}
end
def awm
m = method(:x=)
#{'m.call(nil);'*256}
end
END
end
obj = C.new
benchmark:
attr_reader: "obj.ar"
attr_writer: "obj.aw"
attr_reader_method: "obj.arm"
attr_writer_method: "obj.awm"