Project

General

Profile

Actions

Feature #19287

open

Let DelegateClass respect the original method's arity in case of 0

Added by matsuda (Akira Matsuda) over 1 year ago. Updated 8 months ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:111523]

Description

As reported in #19165, method delegation with *, **, and ... adds some overhead for a method that takes no argument. And current implementation of delegations in forwardable and delegate basically define all methods to take splat parameters.

But, with regard to DelegateClass, we can investigate the arity of the target methods in the initializer, then we can define the delegation method not to take the splat for zero arity methods.

A benchmark on trunk today results in 37% runtime performance improvement on a such method.

Benchmark:
Warming up --------------------------------------
old 551.697k i/100ms
new 721.906k i/100ms
Calculating -------------------------------------
old 6.511M (± 0.8%) i/s - 33.102M in 5.084530s
new 8.925M (± 1.0%) i/s - 44.758M in 5.015619s

Comparison:
new: 8924652.2 i/s
old: 6510691.1 i/s - 1.37x (± 0.00) slower

Patch: https://github.com/ruby/ruby/pull/7045

Updated by matsuda (Akira Matsuda) over 1 year ago

I should have posted the patch to delegate's own repo. Reposted the same patch to https://github.com/ruby/delegate/pull/16

Actions #2

Updated by jeremyevans0 (Jeremy Evans) 8 months ago

  • Tracker changed from Bug to Feature
  • ruby -v deleted (ruby 3.3.0dev (2022-12-28T16:43:05Z master cada537040) +YJIT [arm64-darwin21])
  • Backport deleted (2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN)
Actions

Also available in: Atom PDF

Like0
Like0Like0