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 range
2+#
3+# Hot loop iterates `(1..500_000_000).each` accumulating
4+# `sum + (i % 7)` per iteration. The `% 7` introduces a
5+# sequential data dependency on the loop body so the C
6+# compiler cannot collapse the loop to a closed form.
7+#
8+# Tests Spinel's Range#each lowering: a literal numeric range
9+# should fuse to a tight C `for` loop with bounds inlined,
10+# avoiding the `sp_Range` struct allocation+access of the
11+# generic `each` path.
12+
13+sum = 0
14+(1..500_000_000).each { |i| sum = sum + (i % 7) }
15+puts sum