-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Improve yielding block performance #1535
Conversation
Use |
The yielding block will be faster around 9%. This patch ensures that expand to inline codes in where invoke yielding block. * Environment - macOS 10.12.3 - clang 8.0.0 in Xcode 8.2 * Before user system total real Integer#times 0.930000 0.000000 0.930000 ( 0.932125) Array#each 0.950000 0.000000 0.950000 ( 0.957962) Array#map 1.220000 0.030000 1.250000 ( 1.249174) * After user system total real Integer#times 0.850000 0.000000 0.850000 ( 0.853202) Array#each 0.860000 0.010000 0.870000 ( 0.865507) Array#map 1.120000 0.020000 1.140000 ( 1.149939) * Test code require 'benchmark' Benchmark.bmbm do |x| ary = (1..10000).to_a x.report "Integer#times" do 20000000.times do end end x.report "Array#each" do 2000.times do ary.each { |x| } end end x.report "Array#map" do 2000.times do ary.map { |x| } end end end
@nobu Thank you for your review. Updated the code with your suggestion. |
This patch improves performance in where invoke blocks with other case. bm_app_lc_fizzbuzz.rb will be faster around 5%. * Before ``` $ ruby benchmark/run.rb --ruby=./miniruby --only-ruby bm_app_lc_fizzbuzz MatzRuby: Ruby: ruby 2.5.0dev (2017-03-08 yield 57806) [x86_64-darwin16] last_commit=Improve yielding block performance app_lc_fizzbuzz: ruby 77.322 -- benchmark summary --------------------------- app_lc_fizzbuzz 77.322 ``` * After ``` $ ruby benchmark/run.rb --ruby=./miniruby --only-ruby bm_app_lc_fizzbuzz MatzRuby: Ruby: ruby 2.5.0dev (2017-03-08 yield 57806) [x86_64-darwin16] last_commit=Improve yielding block performance app_lc_fizzbuzz: ruby 72.187 -- benchmark summary --------------------------- app_lc_fizzbuzz 72.187 ```
Integer#times will be faster around 7% on macOS + clang environment. * Before user system total real 2.310000 0.000000 2.310000 ( 2.315654) * After user system total real 2.150000 0.000000 2.150000 ( 2.153181) * Test code require 'benchmark' Benchmark.bmbm do |x| x.report do 50000000.times do end end end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For me, 9% is not enough large improvement for such a ugly optimization.
I think this pull request is related to https://bugs.ruby-lang.org/issues/12599 If |
If some functions which is expected to be inlined like |
It seems to have a conflict now. Could you rebase this from master? |
Let me close this as it has not been updated for a while. Please reopen this after resolving conflicts. Thanks. |
The yielding block will be faster around 9%.
This patch ensures that expand to inline codes in where invoke yielding block.
Environment
Before
https://bugs.ruby-lang.org/issues/13342