Project

General

Profile

Actions

Feature #13342

open

Improve yielding block performance

Feature #13342: Improve yielding block performance

Added by watson1978 (Shizuo Fujita) over 8 years ago. Updated over 6 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-dev:50025]

Description

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 

Patch

The patch is in https://github.com/ruby/ruby/pull/1535

Updated by watson1978 (Shizuo Fujita) over 8 years ago Actions #1 [ruby-dev:50077]

When I filed this ticket, I tried to run benchmark on macOS + clang only.
Then, I tried to do on 2 environments in additional.

macOS 10.12 + gcc 6.3.0

Before

 user system total real Integer#times 0.890000 0.000000 0.890000 ( 0.886378) Array#each 0.840000 0.010000 0.850000 ( 0.849755) Array#map 1.070000 0.030000 1.100000 ( 1.094257) 

After

 user system total real Integer#times 0.860000 0.000000 0.860000 ( 0.860164) Array#each 0.870000 0.000000 0.870000 ( 0.867758) Array#map 1.070000 0.030000 1.100000 ( 1.102324) 

Ubuntu 16.04.4 + gcc 5.4.0

Before

 user system total real Integer#times 0.560000 0.000000 0.560000 ( 0.561627) Array#each 0.550000 0.000000 0.550000 ( 0.552468) Array#map 0.710000 0.000000 0.710000 ( 0.714104) 

After

 user system total real Integer#times 0.530000 0.000000 0.530000 ( 0.533428) Array#each 0.530000 0.000000 0.530000 ( 0.526173) Array#map 0.650000 0.020000 0.670000 ( 0.676441) 

Updated by jeremyevans0 (Jeremy Evans) over 6 years ago Actions #2

  • Tracker changed from Bug to Feature
  • Backport deleted (2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN)
Actions

Also available in: PDF Atom