• dearblue's avatar
    Drop unnecessary upper procs linked from class/module/def syntax · 59201b59
    dearblue authored
    It does not need to hold an anonymous proc for constant search.
    Also, this change can be expected to cause an anonymous proc to be GC'd.
    
    This is useful for metaprogramming that makes heavy use of the `class`/`module`/`def` syntax in the `class_eval`/`eval` method.
    
    Example:
    
    - code
    
      ```ruby
      p ObjectSpace.count_objects
    
      String.class_eval do
        def a
        end
      end
    
      p ObjectSpace.count_objects
    
      String.class_eval do
        eval <<~CODE
          def b
          end
        CODE
      end
    
      p ObjectSpace.count_objects
      ```
    
    - result of building mruby-head (d63c0df6) with `build_config/default.rb`
    
      ```
      {:TOTAL=>1024, :FREE=>262, :T_PROC=>495, :T_ENV=>61, ...}
      {:TOTAL=>1024, :FREE=>259, :T_PROC=>497, :T_ENV=>62, ...}
      {:TOTAL=>1024, :FREE=>255, :T_PROC=>500, :T_ENV=>63, ...}
      ```
    
    - result of building mruby with this patch and `build_config/default.rb`
    
      ```
      {:TOTAL=>1024, :FREE=>264, :T_PROC=>494, :T_ENV=>60, ...}
      {:TOTAL=>1024, :FREE=>262, :T_PROC=>495, :T_ENV=>61, ...}
      {:TOTAL=>1024, :FREE=>261, :T_PROC=>496, :T_ENV=>61, ...}
      ```
    59201b59
vm.c 79.1 KB