From: ivo.wever@... Date: 2021-04-01T19:25:42+00:00 Subject: [ruby-core:103158] [Ruby master Bug#17772] Performance issue with NameError message in context with large instance variables (not caused by did_you_mean) Issue #17772 has been reported by Confusion (Ivo Wever). ---------------------------------------- Bug #17772: Performance issue with NameError message in context with large instance variables (not caused by did_you_mean) https://bugs.ruby-lang.org/issues/17772 * Author: Confusion (Ivo Wever) * Status: Open * Priority: Normal * ruby -v: ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux] * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN ---------------------------------------- The following script takes about 2 seconds (tested on 2.6.6 and 2.7.2) to get from 'rescue' to 'ensure' on my machine, when executed as `ruby --disable-did_you_mean script.rb`. The time is taken by getting the `e.message`. ``` class Environment def run @data = (1..5_000_000).to_h {|x| [x, x]} trigger_name_error rescue Exception => e start = Time.now e.message ensure puts "In ensure after #{Time.now - start}" end end Environment.new.run ``` The time is much lower if you: * change the instance variable to a local variable * change #run to a class method * trigger something other than a NameError The time is roughly linear in the size of @data. The time roughly doubles if you enable `did_you_mean`. Since I'm regularly operating in such contexts with large instance variables, I noted the slowness of NameErrors and went looking for the cause, whittling it down to the above script. Not sure if this should be considered a bug, but I guess it is probably undesirable? -- https://bugs.ruby-lang.org/ Unsubscribe: