🗂

[bugs.ruby][Bug #20299] TracePoint を無効にした後も有効なままになるケースがあるというバグ報告

2024/03/09に公開

[Bug #20299] Tracepoint staying enable after a disable

  • TracePoint を無効にした後も有効になったままになっているというバグ報告
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
$ 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
  • Ruby 3.2 だとまた結果が異なる
$ 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
  • 遅い = 有効のままになっている、ってことなんですかねー
  • 割と影響が大きそう
GitHubで編集を提案

Discussion