From: Ayumu AIZAWA Date: 2012-01-07T22:48:50+09:00 Subject: [ruby-core:41957] [Backport93 - Backport #5835] Please Backport r34202 and r34204 (rexml BaseParser uses instance_eval unnecessarily on listener add) Issue #5835 has been updated by Ayumu AIZAWA. Merged by r3224 r3223 ---------------------------------------- Backport #5835: Please Backport r34202 and r34204 (rexml BaseParser uses instance_eval unnecessarily on listener add) https://bugs.ruby-lang.org/issues/5835 Author: Charles Nutter Status: Open Priority: Normal Assignee: Category: Target version: In add_listener in REXML::BaseParser, there's code to instance eval and replace the old "pull" method with a new one that calls all listeners. I assume this was done to avoid the cost of calling .each on the listeners when there's none registered, but when the list is empty this call is nearly a no-op anyway. The singletonizing effect of instance_eval and the redefinition of #pull, on the other hand, cause a cache flush throughout the system. I have created a patch that removes the instance_eval, initializes the listeners array unconditionally, and does the event #each unconditionally. It passes all tests, and should perform better because it's not damaging the cache. https://gist.github.com/1420383 This can be safely backported to any Ruby version and has no visible behavior change. -- http://redmine.ruby-lang.org