Skip to content

Conversation

k0kubun
Copy link
Member

@k0kubun k0kubun commented Aug 29, 2025

This PR propagates compile-error reasons all the way up and counts them at run-time instead of at compile time.

I also changed the order of print_counters_with_prefix since unhandled_yarv_insn_ isn't that important compared to compile_error_ at the moment, and placing exit_ from the rest didn't seem useful. (past discussion)

Example

On lobsters,

***ZJIT: Printing ZJIT statistics on exit***
Top-6 unhandled call types (100.0% of total 187,316):
     block_arg: 97,210 (51.9%)
         kwarg: 63,056 (33.7%)
         splat: 14,235 ( 7.6%)
      kw_splat: 12,372 ( 6.6%)
     splat_mut:    279 ( 0.1%)
  kw_splat_mut:    164 ( 0.1%)
Top-17 unhandled YARV insns (100.0% of total 1,467,641):
         invokesuper: 588,816 (40.1%)
         invokeblock: 336,957 (23.0%)
  getblockparamproxy: 310,670 (21.2%)
        checkkeyword:  88,575 ( 6.0%)
         expandarray:  79,860 ( 5.4%)
   opt_case_dispatch:  47,572 ( 3.2%)
    getclassvariable:   9,910 ( 0.7%)
       getblockparam:   3,387 ( 0.2%)
         sendforward:     772 ( 0.1%)
         getconstant:     452 ( 0.0%)
          checkmatch:     351 ( 0.0%)
   opt_duparray_send:     133 ( 0.0%)
  invokesuperforward:     115 ( 0.0%)
                once:      23 ( 0.0%)
        definemethod:      20 ( 0.0%)
         defineclass:      14 ( 0.0%)
    setclassvariable:      14 ( 0.0%)
Top-4 compile error reasons (100.0% of total 1,922,353):
     parse_parameter_type_optional: 1,170,078 (60.9%)
           register_spill_on_alloc:   369,952 (19.2%)
  parse_parameter_type_forwardable:   256,154 (13.3%)
           register_spill_on_ccall:   126,169 ( 6.6%)
Top-10 side exit reasons (100.0% of total 7,179,512):
     guard_shape_failure: 2,245,518 (31.3%)
           compile_error: 1,922,353 (26.8%)
     unhandled_yarv_insn: 1,467,641 (20.4%)
      guard_type_failure: 1,091,232 (15.2%)
              patchpoint:   232,895 ( 3.2%)
     unhandled_call_type:   187,316 ( 2.6%)
      unhandled_hir_insn:    15,955 ( 0.2%)
   unknown_newarray_send:     9,374 ( 0.1%)
  obj_to_string_fallback:     7,201 ( 0.1%)
               interrupt:        27 ( 0.0%)
dynamic_send_count:  10,019,054
compiled_iseq_count: 6,393
failed_iseq_count:   963
compile_time:        5,726ms
profile_time:        59ms
gc_time:             66ms
invalidation_time:   11ms
code_region_bytes:   7,454,720
side_exit_count:     7,179,512
total_insn_count:    169,506,517
vm_insn_count:       80,033,095
zjit_insn_count:     89,473,422
ratio_in_zjit:       52.8%

@k0kubun k0kubun force-pushed the zjit-failure-stats branch 5 times, most recently from 0956e53 to 22cf464 Compare August 29, 2025 22:57
@k0kubun k0kubun force-pushed the zjit-failure-stats branch from 22cf464 to 7c78022 Compare August 29, 2025 23:10
@k0kubun k0kubun marked this pull request as ready for review August 29, 2025 23:13
@matzbot matzbot requested a review from a team August 29, 2025 23:14
@k0kubun k0kubun merged commit bdaff44 into ruby:master Sep 2, 2025
87 checks passed
@k0kubun k0kubun deleted the zjit-failure-stats branch September 2, 2025 18:28
Comment on lines +1643 to +1648
let code_ptr = match code_ptr {
Ok(code_ptr) => code_ptr,
Err(compile_error) => {
prepare_for_exit(iseq, cfp, sp, &compile_error);
ZJITState::get_exit_trampoline_with_counter()
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let code_ptr = match code_ptr {
Ok(code_ptr) => code_ptr,
Err(compile_error) => {
prepare_for_exit(iseq, cfp, sp, &compile_error);
ZJITState::get_exit_trampoline_with_counter()
}
let code_ptr = code_ptr.unwrap_or_else(|compile_error| {
prepare_for_exit(iseq, cfp, sp, &compile_error);
ZJITState::get_exit_trampoline_with_counter()
};

This may be less line noise and more idiomatic

Comment on lines +116 to 122
let start_ptr = match gen_iseq(cb, iseq, Some(&function)) {
Ok(start_ptr) => start_ptr,
Err(err) => {
debug!("Failed to compile iseq: gen_iseq failed: {}", iseq_get_location(iseq, 0));
return Err(err);
}
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let start_ptr = match gen_iseq(cb, iseq, Some(&function)) {
Ok(start_ptr) => start_ptr,
Err(err) => {
debug!("Failed to compile iseq: gen_iseq failed: {}", iseq_get_location(iseq, 0));
return Err(err);
}
};
let start_ptr = match gen_iseq(cb, iseq, Some(&function))
.inspect_err(|_| {
debug!("Failed to compile iseq: gen_iseq failed: {}", iseq_get_location(iseq, 0));
})?;

This is supported as of 1.76.0 and is slightly more idiomatic.

@aidenfoxivey
Copy link
Contributor

Ah whoops, was a bit late on submitting my comments.

@k0kubun
Copy link
Member Author

k0kubun commented Sep 2, 2025

will file a separate PR to address them, thanks!

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.

3 participants