Backport #8143
closed[patch] forwardable: reduce allocations in def_delegators wrappers
Description
$ ./ruby -Ilib -rpp -rforwardable -e '
module Test
extend Forwardable
def_delegators :@test, *("a".."z")
end
GC.start
strings = ObjectSpace.each_object(String).select{ |s| s.frozen? && s =~ /forwardable/ }
p strings.size
pp strings.inject(Hash.new 0){ |h,s| h[s]+=1; h }
'
before:
73
[["/Users/test/code/ruby\\-trunk/lib/forwardable\\.rb", 26],
["/Users/test/code/ruby-trunk/lib/forwardable.rb", 33]]
after:
46
[["/Users/test/code/ruby-trunk/lib/forwardable.rb", 31],
["/Users/test/code/ruby-trunk/lib/forwardable", 1]]
diff --git a/lib/forwardable.rb b/lib/forwardable.rb
index d7116ed..2bd67f6 100644
--- a/lib/forwardable.rb
+++ b/lib/forwardable.rb
@@ -102,6 +102,7 @@ module Forwardable
Version of +forwardable.rb+¶
FORWARDABLE_VERSION = "1.1.0"
- FILE_REGEXP = %r"#{Regexp.quote(FILE)}"o
@debug = nil
class << selfIf true, FILE will remain in the backtrace in the event an¶
@@ -170,7 +171,7 @@ module Forwardable
begin
#{accessor}.send(:#{method}, *args, &block)
rescue Exception
-
$@.delete_if{|s| %r"#{Regexp.quote(__FILE__)}"o =~ s} unless Forwardable::debug
-
$@.delete_if{|s| Forwardable::FILE_REGEXP =~ s} unless Forwardable::debug ::Kernel::raise end end
@@ -262,7 +263,7 @@ module SingleForwardable
begin
#{accessor}.send(:#{method}, *args, &block)
rescue Exception
-
$@.delete_if{|s| %r"#{Regexp.quote(__FILE__)}"o =~ s} unless Forwardable::debug
-
$@.delete_if{|s| Forwardable::FILE_REGEXP =~ s} unless Forwardable::debug ::Kernel::raise end end
Updated by nobu (Nobuyoshi Nakada) about 11 years ago
- Status changed from Open to Closed
- % Done changed from 0 to 100
This issue was solved with changeset r39875.
Aman, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
forwardable.rb: reduce allocations in def_delegators
- lib/forwardable.rb (Forwardable::FILE_REGEXP): create regexp object
outside sources for eval, to reduce allocations in def_delegators
wrappers. //o option does not make each regexps shared. patch by
tmm1 (Aman Gupta) in [ruby-core:53620] [Bug #8143].
Updated by tmm1 (Aman Karmani) almost 11 years ago
- Tracker changed from Bug to Backport
- Project changed from Ruby master to Backport200
- Status changed from Closed to Open
Updated by tmm1 (Aman Karmani) almost 11 years ago
- Status changed from Open to Assigned
- Assignee set to nagachika (Tomoyuki Chikanaga)
- % Done changed from 100 to 0
Updated by naruse (Yui NARUSE) almost 8 years ago
- Status changed from Assigned to Rejected