Project

General

Profile

Bug #13111

Degraded performance for delegated methods through Forwardable module

Added by gonzedge (Edgar Gonzalez) over 2 years ago. Updated about 2 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:79002]

Description

After upgrading to Ruby 2.4.0 on my local machine while developing some changes on this gem: https://github.com/gonzedge/rambling-trie, there was a noticeable performance degradation with any delegated methods through Forwardable. I have a few benchmarks in place and, without changing any other code, had a ~25% increase in the time it took to execute.

If you look at the benchmarks on https://github.com/gonzedge/rambling-trie/blob/master/reports/0.9.2/benchmark and https://github.com/gonzedge/rambling-trie/blob/master/reports/0.9.3/benchmark, you'll notice that the first benchmark (for Rambling::Trie.create) goes from 8.97 seconds to 11.19 seconds. These benchmarks are generated by running rake performance:benchmark:all.

Associated revisions

Revision 7ed75492
Added by naruse (Yui NARUSE) about 2 years ago

merge revision(s) 57255,57256,57257: [Backport #13111]

    forwardable.rb: use defined?

    * lib/forwardable.rb (_delegator_method): use defined? operator
      instead of binding and calling unbound Kernel#respond_to?.  a
      remedy for an performance bottleneck.
    forwardable.rb: use defined?

    * lib/forwardable.rb (_delegator_method): use defined? operator
      instead of binding and calling unbound Kernel#respond_to?.  a
      remedy for an performance bottleneck.
    forwardable.rb: fix branches

    * lib/forwardable.rb (instance_delegate, single_delegate): fix
      inverted branches.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_4@57913 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 57913
Added by naruse (Yui NARUSE) about 2 years ago

merge revision(s) 57255,57256,57257: [Backport #13111]

forwardable.rb: use defined?

* lib/forwardable.rb (_delegator_method): use defined? operator
  instead of binding and calling unbound Kernel#respond_to?.  a
  remedy for an performance bottleneck.
forwardable.rb: use defined?

* lib/forwardable.rb (_delegator_method): use defined? operator
  instead of binding and calling unbound Kernel#respond_to?.  a
  remedy for an performance bottleneck.
forwardable.rb: fix branches

* lib/forwardable.rb (instance_delegate, single_delegate): fix
  inverted branches.

History

Updated by gonzedge (Edgar Gonzalez) over 2 years ago

Update:

I talked to @Yuki Nishijima and he pointed out that it is an issue with an UnboundMethod instance being created on every delegated call here: https://github.com/ruby/ruby/blob/2283d14cc9fefa278dfde02bdf8d84ce50cfe16f/lib/forwardable.rb#L207 (thanks, Yuki!)

Also, I saw that the issue has been fixed on the trunk branch in revisions 57255, 57256 & 57257 (thanks, @Nobuyoshi Nakada!).

So, I'm inclined to ask: Will this fix be ported back to Ruby 2.4? Either way, how soon would a new version with the fix be released?

Updated by shyouhei (Shyouhei Urabe) over 2 years ago

  • Backport changed from 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN to 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: REQUIRED
  • Status changed from Open to Closed

Let me close (closed issues are inspected by branch mentors to backport-ability). I guess this is a subject to backport.

Updated by naruse (Yui NARUSE) about 2 years ago

  • Backport changed from 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: REQUIRED to 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: DONE

ruby_2_4 r57913 merged revision(s) 57255,57256,57257.

Also available in: Atom PDF