Project

General

Profile

Actions

Bug #20299

open

Tracepoint staying enable after a disable

Added by MaxLap (Maxime Lapointe) 9 months ago. Updated 9 months ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:116939]

Description

Problem is present in Ruby 3.2.2, 3.2.3, 3.3.0. Didn't check before.

It seems that TracePoint can sometime be "stuck" enabled after using disabled once on it.

Here is a reproduction step using a "check speed" method that just does some work and print out how long it takes. This makes it pretty clear when TracePoint was on.

Put this in a Ruby file:

def check_speed(msg)
  t1 = Time.now.to_f
  a = 0
  1000000.times { |i|
    a += 10
  }
  t2 = Time.now.to_f
  puts "#{t2-t1} - #{msg}"
end

check_speed("before") # fast

trace = TracePoint.new(:line) {}
trace.enable

check_speed("after enable") # slow
trace.enable {
  check_speed("in block enable") # slow
}
check_speed("after block enable") # slow

trace.disable
check_speed("after disable") # slow !!!!

trace.disable
check_speed("after disable again") # fast !!!!

# And yet, using enable multiple time doesn't have a "counter" or similar
trace.enable
trace.enable
trace.enable
check_speed("after triple enable") # slow
trace.disable
check_speed("after single disable") # fast

Running the file, we get this:

$ ruby -v
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-linux]
$ ruby local.rb
0.03473854064941406 - before
0.18935227394104004 - after enable
0.17757630348205566 - in block enable
0.18320131301879883 - after block enable
0.1818866729736328 - after disable
0.03412747383117676 - after disable again
0.18405628204345703 - after triple enable
0.033496856689453125 - after single disable

The first "after disable" should probably have been fast. If it's possible to have multiple nested enable/disable, then one would instead assume that after the last "single disable", things would still be slow.

Note: This code patterns comes directly for a ruby/spec: ctrl+f for "enables trace object on calling with a block if it was already enabled"

I note that in Ruby 3.2, the timing are a lot less similar. I don't know why. It would seem like TracePoint got slower in Ruby 3.3.0. Is that worth checking out / making a distincct bug for?

$ rvm use 3.2.3
Using /home/max/.rvm/gems/ruby-3.2.3
$ ruby local.rb
0.03246927261352539 - before
0.07910513877868652 - after enable
0.10309600830078125 - in block enable
0.12397646903991699 - after block enable
0.07114601135253906 - after disable
0.028218746185302734 - after disable again
0.12534689903259277 - after triple enable
0.02810525894165039 - after single disable
Actions

Also available in: Atom PDF

Like0
Like0Like0