Commit a211abb
authored
Cache array length in
When all elements are strings, we never have to recalculate the length
of the array because there are no conversion methods that are called, so
the length will never change. This speeds up the fast path by ~10%.
```ruby
a = ["1"*10, "2"*10, "3"*10, "4"*10, "5"*10] * 10
10_000_000.times do
a.join
end
```
```
hyperfine --warmup 1 'ruby ../ruby2/test.rb' './exe/ruby ../ruby2/test.rb'
Benchmark 1: ruby ../ruby2/test.rb
Time (mean ± σ): 3.779 s ± 0.053 s [User: 3.754 s, System: 0.017 s]
Range (min … max): 3.715 s … 3.874 s 10 runs
Benchmark 2: ./exe/ruby ../ruby2/test.rb
Time (mean ± σ): 3.411 s ± 0.038 s [User: 3.387 s, System: 0.017 s]
Range (min … max): 3.360 s … 3.472 s 10 runs
Summary
./exe/ruby ../ruby2/test.rb ran
1.11 ± 0.02 times faster than ruby ../ruby2/test.rb
```rb_ary_join (ruby#15362)1 parent a63147e commit a211abb
1 file changed
+20
-15
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2917 | 2917 | | |
2918 | 2918 | | |
2919 | 2919 | | |
2920 | | - | |
| 2920 | + | |
| 2921 | + | |
2921 | 2922 | | |
2922 | | - | |
2923 | | - | |
2924 | | - | |
2925 | | - | |
2926 | | - | |
2927 | | - | |
2928 | | - | |
2929 | | - | |
2930 | | - | |
2931 | | - | |
2932 | | - | |
2933 | | - | |
| 2923 | + | |
| 2924 | + | |
| 2925 | + | |
| 2926 | + | |
| 2927 | + | |
| 2928 | + | |
| 2929 | + | |
| 2930 | + | |
| 2931 | + | |
| 2932 | + | |
| 2933 | + | |
| 2934 | + | |
| 2935 | + | |
| 2936 | + | |
| 2937 | + | |
| 2938 | + | |
| 2939 | + | |
| 2940 | + | |
2934 | 2941 | | |
2935 | | - | |
2936 | | - | |
2937 | 2942 | | |
2938 | 2943 | | |
2939 | 2944 | | |
| |||
0 commit comments