Skip to content
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

Using define method instead of class eval when defining model callbacks. #10524

Merged
merged 1 commit into from May 8, 2013

Conversation

wangjohn
Copy link
Contributor

@wangjohn wangjohn commented May 8, 2013

Based on my benchmark results, this change improves performance
substantially when defining callbacks (especially for apps that are defining large numbers of callbacks).

This benchmark (https://gist.github.com/wangjohn/5542610) was run using
the current master and also using my experimental branch which replaced
class_eval with define_single_method.

Using class_eval (current master):

                    user     system      total        real
10 trials       0.000000   0.000000   0.000000 (  0.001568)
50 trials       0.020000   0.000000   0.020000 (  0.021715)
500 trials      0.110000   0.000000   0.110000 (  0.115357)
1000 trials     0.250000   0.000000   0.250000 (  0.260025)
10000 trials    2.560000   0.000000   2.560000 (  2.568408)
50000 trials   12.800000   0.010000  12.810000 ( 12.886871)

Using define_single_method (experimental branch):

                    user     system      total        real
10 trials       0.000000   0.000000   0.000000 (  0.000790)
50 trials       0.000000   0.000000   0.000000 (  0.002960)
500 trials      0.050000   0.010000   0.060000 (  0.055690)
1000 trials     0.100000   0.000000   0.100000 (  0.094073)
10000 trials    0.890000   0.000000   0.890000 (  0.900364)
50000 trials    4.650000   0.000000   4.650000 (  4.686127)

Based on my benchmark results, this change improves performance
substantially when defining callbacks.

This benchmark (https://gist.github.com/wangjohn/5542610) was run using
the current master and also using my experimental branch which replaced
class_eval with define_single_method.

Using class_eval (current master):

                    user     system      total        real
10 trials       0.000000   0.000000   0.000000 (  0.001568)
50 trials       0.020000   0.000000   0.020000 (  0.021715)
500 trials      0.110000   0.000000   0.110000 (  0.115357)
1000 trials     0.250000   0.000000   0.250000 (  0.260025)
10000 trials    2.560000   0.000000   2.560000 (  2.568408)
50000 trials   12.800000   0.010000  12.810000 ( 12.886871)

Using define_single_method (experimental branch):

                    user     system      total        real
10 trials       0.000000   0.000000   0.000000 (  0.000790)
50 trials       0.000000   0.000000   0.000000 (  0.002960)
500 trials      0.050000   0.010000   0.060000 (  0.055690)
1000 trials     0.100000   0.000000   0.100000 (  0.094073)
10000 trials    0.890000   0.000000   0.890000 (  0.900364)
50000 trials    4.650000   0.000000   4.650000 (  4.686127)
rafaelfranca added a commit that referenced this pull request May 8, 2013
Using define method instead of class eval when defining model callbacks.
@rafaelfranca rafaelfranca merged commit f4c96fe into rails:master May 8, 2013
@wangjohn wangjohn deleted the define_method_for_callbacks branch May 8, 2013 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants