From: os97673@... Date: 2014-12-03T11:39:25+00:00 Subject: [ruby-core:66658] [ruby-trunk - Bug #10511] fix for #9940 causes dramatic performance regression Issue #10511 has been updated by Oleg Sukhodolsky. I think I've found one more source of performance degradation: in debase we keep contexts for threads in hash and on every event get them from there. And it looks like "hash[Thread.current]" became significantly slower in TracePoint's hendler's context. Here is a simple test which shows the problem: `require 'benchmark' N = 10000 RECURSION = 1000 def recurse(i) recurse(i - 1) if i > 0 end theHash = Hash.new TracePoint.new(:call, :return, :c_call, :c_return, :line){|tp| tp.lineno theHash[Thread.current] }.enable puts Benchmark.measure { N.times { recurse(RECURSION) } } ` in my case it shows: $ rvm ruby-2.1.2 do ruby /tmp/bm.rb 44.080000 0.330000 44.410000 ( 45.207792) $ rvm ruby-head do ruby /tmp/bm.rb 72.170000 2.040000 74.210000 ( 76.259147) Note: I've tried to replace "theHash[Thread.current]" with either "theHash[1]" or "Thread.current.hash" but such tests do not show any performance degradation, it looks like it is a combination of hash access and thread causes the problem. ---------------------------------------- Bug #10511: fix for #9940 causes dramatic performance regression https://bugs.ruby-lang.org/issues/10511#change-50269 * Author: Oleg Sukhodolsky * Status: Feedback * Priority: Normal * Assignee: Koichi Sasada * Category: core * Target version: current: 2.2.0 * ruby -v: ruby 2.1.3p242 (2014-09-19 revision 47630) [x86_64-darwin14.0] * Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN ---------------------------------------- Originally reported against debase gem (https://github.com/denofevil/debase/issues/16) After fix for #9940 running anything under debugger became about 4 times slower. I've verified that we I revert the fix performance is restored. To reproduce you could get https://github.com/railstutorial/sample_app_rails_4 and run rspec rake task under debugger (I've used RubyMine for this because debase is used as debugger's backend there) Performance with 2.1.2 it takes about 20 seconds on my laptop, with 2.1.3 - almost 80 seconds :( The same problem is observable with 2.1.4 and 2.1.5 too. -- https://bugs.ruby-lang.org/