Commit bc2ef131
bc2ef1312b8dMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 4 files · +3 added · ~1 modified
Description
Merge pull request #477 from ryanseys/rs-perf-range-each-fusion
perf(codegen): fuse Range#each over literal numeric range to C for-loop
Details
- Commit
- bc2ef1312b8d
- Parent
- 56b09e11c8f9
- Merge parent
- 82b26e2d41b5
benchmark/bm_range_each.rbaddedView file
1+
# bm_range_each - Range#each over a literal numeric range2+
#3+
# Hot loop iterates `(1..500_000_000).each` accumulating4+
# `sum + (i % 7)` per iteration. The `% 7` introduces a5+
# sequential data dependency on the loop body so the C6+
# compiler cannot collapse the loop to a closed form.7+
#8+
# Tests Spinel's Range#each lowering: a literal numeric range9+
# should fuse to a tight C `for` loop with bounds inlined,10+
# avoiding the `sp_Range` struct allocation+access of the11+
# generic `each` path.12+
13+
sum = 014+
(1..500_000_000).each { |i| sum = sum + (i % 7) }15+
puts sumspinel_codegen.rbmodifiedView file
Loading diff…
test/range_each_fusion.rbaddedView file
Loading diff…
test/range_each_fusion.rb.expectedaddedView file
Loading diff…