-
-
Notifications
You must be signed in to change notification settings - Fork 925
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
define_method performance degradation #3391
Comments
This commit might interest you: 3c3055d 9.0.2.0+ will contain this, but it is currently more limited than it needs to be (as outlined in the commit message). So with your sample snippet above we now run that method a couple times faster than 1.7, but many other define_methods will probably show the slowdown you have reported. |
For record here is a benchmark I used for the commit I mentioned above: require 'benchmark/ips'
class Foo
b = 1
define_method(:fooced) do |a|
b
a
end
define_method(:foo) do |a|
a
end
def bar(a)
a
end
end
foo = Foo.new
Benchmark.ips do |x|
x.report "define_method w/ capture" do
foo.fooced(1)
foo.fooced(1)
foo.fooced(1)
foo.fooced(1)
foo.fooced(1)
foo.fooced(1)
foo.fooced(1)
foo.fooced(1)
foo.fooced(1)
foo.fooced(1)
end
x.report "def" do
foo.bar(1)
foo.bar(1)
foo.bar(1)
foo.bar(1)
foo.bar(1)
foo.bar(1)
foo.bar(1)
foo.bar(1)
foo.bar(1)
foo.bar(1)
end
x.report "define_method" do
foo.foo(1)
foo.foo(1)
foo.foo(1)
foo.foo(1)
foo.foo(1)
foo.foo(1)
foo.foo(1)
foo.foo(1)
foo.foo(1)
foo.foo(1)
end
end |
@enebo Thanks for point out that commit, I saw it over the weekend and got super excited. The case that led to creating this issue was a block referencing parent scope which would not take advantage of your optimization. I'm really looking forward to seeing what comes next though :). |
My numbers on @enebo's bench actually seem to show that define_method with capture is currently faster on 9k than on 1.7 (and of course without capture it's way faster now):
Of larger worry is the performance of a plain def here, but that's not related to this bug either. |
I noticed a performance degradation with
define_method
in jruby 9k recently. It sounds like this might have more to do with block overhead with IR in jruby 9k though (#3389 (comment)).Here's what I found:
I'm running these with
--profile.api
flag enabled.1.7:
9k:
There are some occasions where I can get 9k to run as fast as 1.7 for a single test, but the in general, 1.7 seems to be faster than 9k.
Btw, I'm thinking this is block related since
#times
is also much slower on 9k.The text was updated successfully, but these errors were encountered: