Commit 5d1a023
authored
ZJIT: Ensure we specialize the results of the last inlining operation (ruby#17479)
When we introduced the inliner we also added repeated passes of the optimization pipeline. The idea being that we want to optimize the results of inlining and, because we only inline one level deep, allow us to perform inlining on the result of the last inlining operation. The optimization loop would exit if we couldn't inline any more. If we could inline more, there's an upper bound that kicks us out of the loop so we don't try to inline the world. However, if we exited the loop by hitting that upper bound, we didn't end up specializing the results of the last inlining pass. This PR rectifies that.
This is immediately visible in the 30k_methods benchmark, where performance roughly doubles.
Before:
```
❯ WARMUP_ITRS=0 MIN_BENCH_ITRS=10 MIN_BENCH_TIME=0 ./run_benchmarks.rb --chruby 'ruby-master --zjit-inline-threshold=30' 30k_methods
Running benchmark "30k_methods" (1/1)
+ /Users/nirvdrum/.rubies/ruby-master/bin/ruby --zjit-inline-threshold\=30 -I harness /Users/nirvdrum/dev/worktrees/ruby-bench/main/benchmarks/30k_methods.rb
ruby 4.1.0dev (2026-06-23T13:29:36Z master 13fe77d) +ZJIT dev +PRISM [arm64-darwin25]
itr: time
#1: 2689ms
#2: 33ms
#3: 32ms
#4: 32ms
#5: 32ms
#6: 32ms
#7: 32ms
ruby#8: 35ms
ruby#9: 33ms
ruby#10: 33ms
```
After:
```
❯ WARMUP_ITRS=0 MIN_BENCH_ITRS=10 MIN_BENCH_TIME=0 ./run_benchmarks.rb --chruby 'ruby-zjit-opt-last-inline --zjit-inline-threshold=30' 30k_methods
Running benchmark "30k_methods" (1/1)
+ /Users/nirvdrum/.rubies/ruby-zjit-opt-last-inline/bin/ruby --zjit-inline-threshold\=30 -I harness /Users/nirvdrum/dev/worktrees/ruby-bench/main/benchmarks/30k_methods.rb
ruby 4.1.0dev (2026-06-25T13:56:41Z zjit-opt-last-inline 18ce64d) +ZJIT dev +PRISM [arm64-darwin25]
itr: time
#1: 2700ms
#2: 17ms
#3: 16ms
#4: 16ms
#5: 17ms
#6: 16ms
#7: 16ms
ruby#8: 17ms
ruby#9: 16ms
ruby#10: 16ms
```
Fixes Shopify#998.1 parent 18ce64d commit 5d1a023
3 files changed
Lines changed: 81 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6221 | 6221 | | |
6222 | 6222 | | |
6223 | 6223 | | |
6224 | | - | |
6225 | | - | |
6226 | | - | |
6227 | | - | |
6228 | | - | |
6229 | | - | |
| 6224 | + | |
| 6225 | + | |
| 6226 | + | |
| 6227 | + | |
| 6228 | + | |
| 6229 | + | |
| 6230 | + | |
| 6231 | + | |
6230 | 6232 | | |
6231 | 6233 | | |
6232 | 6234 | | |
6233 | 6235 | | |
6234 | 6236 | | |
6235 | 6237 | | |
6236 | | - | |
| 6238 | + | |
| 6239 | + | |
| 6240 | + | |
| 6241 | + | |
| 6242 | + | |
| 6243 | + | |
| 6244 | + | |
6237 | 6245 | | |
6238 | 6246 | | |
6239 | 6247 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17985 | 17985 | | |
17986 | 17986 | | |
17987 | 17987 | | |
| 17988 | + | |
| 17989 | + | |
| 17990 | + | |
| 17991 | + | |
| 17992 | + | |
| 17993 | + | |
| 17994 | + | |
| 17995 | + | |
| 17996 | + | |
| 17997 | + | |
| 17998 | + | |
| 17999 | + | |
| 18000 | + | |
| 18001 | + | |
| 18002 | + | |
| 18003 | + | |
| 18004 | + | |
| 18005 | + | |
| 18006 | + | |
| 18007 | + | |
| 18008 | + | |
| 18009 | + | |
| 18010 | + | |
| 18011 | + | |
| 18012 | + | |
| 18013 | + | |
| 18014 | + | |
| 18015 | + | |
| 18016 | + | |
| 18017 | + | |
| 18018 | + | |
| 18019 | + | |
| 18020 | + | |
| 18021 | + | |
| 18022 | + | |
| 18023 | + | |
| 18024 | + | |
| 18025 | + | |
| 18026 | + | |
| 18027 | + | |
| 18028 | + | |
| 18029 | + | |
| 18030 | + | |
| 18031 | + | |
| 18032 | + | |
| 18033 | + | |
| 18034 | + | |
| 18035 | + | |
| 18036 | + | |
| 18037 | + | |
| 18038 | + | |
| 18039 | + | |
| 18040 | + | |
| 18041 | + | |
| 18042 | + | |
| 18043 | + | |
| 18044 | + | |
| 18045 | + | |
| 18046 | + | |
| 18047 | + | |
17988 | 18048 | | |
17989 | 18049 | | |
17990 | 18050 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
178 | 178 | | |
179 | 179 | | |
180 | 180 | | |
181 | | - | |
182 | | - | |
183 | | - | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
184 | 187 | | |
185 | 188 | | |
186 | 189 | | |
| |||
0 commit comments