Skip to content

ZJIT: Recompile getivar on guard_shape_failure#16589

Merged
k0kubun merged 2 commits into
ruby:masterfrom
k0kubun:zjit-recompile-shape
Apr 3, 2026
Merged

ZJIT: Recompile getivar on guard_shape_failure#16589
k0kubun merged 2 commits into
ruby:masterfrom
k0kubun:zjit-recompile-shape

Conversation

@k0kubun
Copy link
Copy Markdown
Member

@k0kubun k0kubun commented Mar 28, 2026

This PR recompiles getivar on guard_shape_failure exits. The first version compiles the same code as before, but when it gets recompiled and it's a final version, it puts a fallback in the last branch to prevent side exits.

This improves ratio_in_zjit on lobsters from 82.4% to 85.3%.

-Top-18 side exit reasons (100.0% of total 2,329,763):
+Top-18 side exit reasons (100.0% of total 1,869,535):
                    guard_type_failure: 1,570,356 (67.4%)
-                  guard_shape_failure:   523,515 (22.5%)
+                  guard_shape_failure:    56,076 ( 3.0%)
   block_param_proxy_not_iseq_or_ifunc:    51,714 ( 2.2%)
                    unhandled_hir_insn:    45,627 ( 2.0%)
      patchpoint_stable_constant_names:    42,883 ( 1.8%)
           patchpoint_method_redefined:    40,265 ( 1.7%)
                         compile_error:    18,634 ( 0.8%)
             block_param_proxy_not_nil:    12,530 ( 0.5%)

-ratio_in_zjit:                                     82.4%
+ratio_in_zjit:                                     85.3%
before: ruby 4.1.0dev (2026-04-03T16:13:39Z master 892991bdc1) +ZJIT +PRISM [x86_64-linux]
after: ruby 4.1.0dev (2026-04-03T18:36:38Z zjit-recompile-shape dde80408af) +ZJIT +PRISM [x86_64-linux]

--------  ------------  ------------  -------------  ------------
bench      before (ms)    after (ms)  after 1st itr  before/after
lobsters  625.6 ± 1.6%  612.4 ± 1.6%          0.966         1.021
--------  ------------  ------------  -------------  ------------

The rest of guard_shape_failure is from setivar and definedivar. It should be addressed in a follow-up PR.

@k0kubun k0kubun force-pushed the zjit-recompile-shape branch 5 times, most recently from 248781c to cbed8b2 Compare March 30, 2026 20:50
@k0kubun k0kubun marked this pull request as ready for review March 30, 2026 21:17
@matzbot matzbot requested a review from a team March 30, 2026 21:17
@k0kubun k0kubun force-pushed the zjit-recompile-shape branch 6 times, most recently from ed5447e to bf2a2ea Compare April 3, 2026 18:27
@k0kubun k0kubun force-pushed the zjit-recompile-shape branch from bf2a2ea to dde8040 Compare April 3, 2026 18:36
@k0kubun k0kubun changed the title ZJIT: Recompile ivars on guard_shape_failure ZJIT: Recompile getivar on guard_shape_failure Apr 3, 2026
@k0kubun k0kubun requested review from a team and removed request for a team April 3, 2026 20:07
Comment thread zjit/src/codegen.rs Outdated
Address review feedback: use a method instead of directly comparing
.status == IseqStatus::Invalidated.
@k0kubun k0kubun merged commit 6ab9b22 into ruby:master Apr 3, 2026
100 of 105 checks passed
@k0kubun k0kubun deleted the zjit-recompile-shape branch April 3, 2026 22:35
Copy link
Copy Markdown
Contributor

@tekknolagi tekknolagi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh my comments never went through :(

Comment thread zjit/src/hir.rs
let self_val = self.load_ivar_guard_type(block, self_val, recv_type, state);
let shape = self.load_shape(block, self_val);
self.guard_shape(block, shape, recv_type.shape(), state);
self.guard_shape(block, shape, recv_type.shape(), state, Some(-1));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This Some(-1) vs None stuff is kind of hard to read & reason about. Can we fix that API?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like this? #16665

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ZJIT: Recompile ISEQ when a shape check fails on monomorphic callsites

3 participants