Issue #8143 has been reported by tmm1 (Aman Gupta).

----------------------------------------
Bug #8143: [patch] forwardable: reduce allocations in def_delegators wrappers
https://bugs.ruby-lang.org/issues/8143

Author: tmm1 (Aman Gupta)
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 
ruby -v: ruby 2.1.0dev (2013-03-22 trunk 39872) [x86_64-darwin12.2.1]


$ ./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 << self
     # If true, <tt>__FILE__</tt> 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



-- 
http://bugs.ruby-lang.org/