Commit b84190e
committed
ZJIT: Pass a
`bar(&blk)` only became a direct send when ZJIT could prove `blk` was nil.
Anything else kept the site on `rb_vm_send`, which pays a method search, an
interpreter frame push and a `vm_exec` setjmp on every call. On lobsters that
is 2.06M of the 12.0M dynamic sends a run -- 17% of them -- concentrated in
Rails' `def _read_attribute(name, &block) = @attributes.fetch_value(name,
&block)` style forwarding methods.
`vm_caller_setup_arg_block` produces the callee's block handler from the block
argument, and two of its cases need no work at run time:
* A `Proc` is its own block handler, so a guard on the argument's class is
enough to write it into the callee frame's specval.
* `rb_block_param_proxy` resolves to `VM_CF_BLOCK_HANDLER(cfp)`, this frame's
own block handler, which is one load off the local EP. That is the case a
`def foo(&blk) = bar(&blk)` site compiles to, because the block parameter is
only ever read as `&blk`.
The proxy reaches the send through the join of `getblockparamproxy`'s
modified/unmodified branches, so its identity is not visible at the send.
Branch on it there instead: `getblockparamproxy` records the value it pushed
for this frame's local EP, and a site that profiled the proxy's (singleton)
class gets an arm that refines the argument to the proxy object, which
`type_specialize` then turns into the EP load. The other side of the branch is
a block parameter that `setblockparam` materialized, which is a legitimate
value to reach the site, so it keeps the dynamic send.
`SendDirect` grows a `block_arg` operand for the resulting handler, and the
inliner declines any call that has one: inlining does not push the callee
frame whose specval would carry it.
On lobsters (10 warmup + 5 bench iterations):
dynamic_send_count 12,001,057 -> 10,527,202 (-12.3%)
send_polymorphic 1,324,915 -> 466,975
send_block_arg_not_nil 692,187 -> 57,695
iseq_optimized_send_count 29,307,998 -> 30,822,668
[zjit/min port note] emit_polymorphic_send() ported without the per-arm profiled-shape
machinery (ARM_SHAPE_MIN_SHARE / as_polymorphic_arm / record_profiled_type) from
excluded commits, so each arm drops the receiver's profile entry the way master's
gen_send_chain does. Keeps master's try_inline_send_direct() entry point, its `cd`
argument to gen_send_iseq_direct(), and its 2-arg gen_block_handler_specval();
SendDirectData gains only `block_arg`, not the excluded `guard_state`.&blk argument through to a direct send1 parent 06770cb commit b84190e
7 files changed
Lines changed: 702 additions & 132 deletions
File tree
- zjit
- bindgen/src
- src
- hir
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
188 | 188 | | |
189 | 189 | | |
190 | 190 | | |
| 191 | + | |
191 | 192 | | |
192 | 193 | | |
193 | 194 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
695 | 695 | | |
696 | 696 | | |
697 | 697 | | |
698 | | - | |
| 698 | + | |
| 699 | + | |
699 | 700 | | |
700 | 701 | | |
701 | 702 | | |
702 | | - | |
| 703 | + | |
703 | 704 | | |
704 | 705 | | |
705 | 706 | | |
| |||
2159 | 2160 | | |
2160 | 2161 | | |
2161 | 2162 | | |
| 2163 | + | |
2162 | 2164 | | |
2163 | 2165 | | |
2164 | 2166 | | |
| |||
2181 | 2183 | | |
2182 | 2184 | | |
2183 | 2185 | | |
2184 | | - | |
2185 | | - | |
2186 | | - | |
2187 | | - | |
2188 | | - | |
| 2186 | + | |
| 2187 | + | |
| 2188 | + | |
| 2189 | + | |
| 2190 | + | |
| 2191 | + | |
| 2192 | + | |
| 2193 | + | |
| 2194 | + | |
| 2195 | + | |
2189 | 2196 | | |
2190 | 2197 | | |
2191 | 2198 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2312 | 2312 | | |
2313 | 2313 | | |
2314 | 2314 | | |
| 2315 | + | |
| 2316 | + | |
| 2317 | + | |
| 2318 | + | |
| 2319 | + | |
| 2320 | + | |
| 2321 | + | |
| 2322 | + | |
| 2323 | + | |
| 2324 | + | |
| 2325 | + | |
| 2326 | + | |
| 2327 | + | |
| 2328 | + | |
| 2329 | + | |
| 2330 | + | |
| 2331 | + | |
| 2332 | + | |
| 2333 | + | |
| 2334 | + | |
| 2335 | + | |
| 2336 | + | |
| 2337 | + | |
| 2338 | + | |
| 2339 | + | |
| 2340 | + | |
| 2341 | + | |
| 2342 | + | |
| 2343 | + | |
| 2344 | + | |
| 2345 | + | |
| 2346 | + | |
| 2347 | + | |
| 2348 | + | |
| 2349 | + | |
| 2350 | + | |
| 2351 | + | |
| 2352 | + | |
| 2353 | + | |
| 2354 | + | |
| 2355 | + | |
| 2356 | + | |
| 2357 | + | |
| 2358 | + | |
| 2359 | + | |
| 2360 | + | |
| 2361 | + | |
| 2362 | + | |
| 2363 | + | |
| 2364 | + | |
| 2365 | + | |
| 2366 | + | |
| 2367 | + | |
| 2368 | + | |
| 2369 | + | |
| 2370 | + | |
| 2371 | + | |
| 2372 | + | |
| 2373 | + | |
| 2374 | + | |
| 2375 | + | |
| 2376 | + | |
| 2377 | + | |
| 2378 | + | |
| 2379 | + | |
| 2380 | + | |
| 2381 | + | |
| 2382 | + | |
| 2383 | + | |
| 2384 | + | |
| 2385 | + | |
| 2386 | + | |
| 2387 | + | |
| 2388 | + | |
| 2389 | + | |
| 2390 | + | |
| 2391 | + | |
| 2392 | + | |
| 2393 | + | |
| 2394 | + | |
| 2395 | + | |
| 2396 | + | |
| 2397 | + | |
| 2398 | + | |
| 2399 | + | |
| 2400 | + | |
| 2401 | + | |
| 2402 | + | |
| 2403 | + | |
| 2404 | + | |
| 2405 | + | |
| 2406 | + | |
| 2407 | + | |
| 2408 | + | |
| 2409 | + | |
| 2410 | + | |
| 2411 | + | |
| 2412 | + | |
| 2413 | + | |
| 2414 | + | |
| 2415 | + | |
| 2416 | + | |
| 2417 | + | |
| 2418 | + | |
| 2419 | + | |
| 2420 | + | |
| 2421 | + | |
| 2422 | + | |
| 2423 | + | |
| 2424 | + | |
| 2425 | + | |
| 2426 | + | |
| 2427 | + | |
| 2428 | + | |
| 2429 | + | |
| 2430 | + | |
| 2431 | + | |
| 2432 | + | |
| 2433 | + | |
| 2434 | + | |
| 2435 | + | |
| 2436 | + | |
| 2437 | + | |
| 2438 | + | |
| 2439 | + | |
| 2440 | + | |
| 2441 | + | |
| 2442 | + | |
| 2443 | + | |
| 2444 | + | |
| 2445 | + | |
| 2446 | + | |
| 2447 | + | |
| 2448 | + | |
| 2449 | + | |
| 2450 | + | |
| 2451 | + | |
| 2452 | + | |
| 2453 | + | |
| 2454 | + | |
| 2455 | + | |
| 2456 | + | |
| 2457 | + | |
| 2458 | + | |
| 2459 | + | |
| 2460 | + | |
| 2461 | + | |
| 2462 | + | |
| 2463 | + | |
| 2464 | + | |
| 2465 | + | |
| 2466 | + | |
| 2467 | + | |
2315 | 2468 | | |
2316 | 2469 | | |
2317 | 2470 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments