Project

General

Profile

Actions

Feature #8576

open

Add optimized method type for constant value methods

Added by Anonymous almost 11 years ago. Updated over 6 years ago.

Status:
Assigned
Target version:
-
[ruby-core:55687]

Description

I've written a patch adding a new method type (VM_METHOD_TYPE_CONSTVAL) for methods that only return a constant value. The patch significantly improves the performance of calls to these types of methods.

I've written a small benchmark script:

require "benchmark"

def foo
  1234
end

puts Benchmark.measure {
  1_000_000.times do
    foo; foo; foo; foo; foo
    foo; foo; foo; foo; foo
  end
}

Before patch:

$ ./rb x.rb
  0.620000   0.000000   0.620000 (  0.625130)

After patch:

$ ./rb x.rb
  0.300000   0.000000   0.300000 (  0.296528)

The patch is here: https://github.com/charliesome/ruby/compare/constant-value-methods

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0