Skip to content

ZJIT: Support calls to non-leaf C functions #759

Description

@aidenfoxivey

In ruby-bench's liquid-render, we note that the majority of def_types are C functions. This could reduce the quantity of send_without_blocks by 10 million, which would be considerable.

***ZJIT: Printing ZJIT statistics on exit***
Top-4 dynamic send types (100.0% of total 41,581,970):
  send_without_block: 32,216,513 (77.5%)
                send:  8,957,394 (21.5%)
         invokeblock:    393,612 ( 0.9%)
         invokesuper:     14,451 ( 0.0%)
Top-4 send fallback def_types (100.0% of total 10,213,585):
      cfunc: 9,993,248 (97.8%)
  optimized:   207,922 ( 2.0%)
    attrset:    12,395 ( 0.1%)
      alias:        20 ( 0.0%)
Top-2 unhandled YARV insns (100.0% of total 144,434):
  getclassvariable: 144,313 (99.9%)
              once:     121 ( 0.1%)
Top-2 compile error reasons (100.0% of total 5,883,100):
  register_spill_on_alloc: 5,882,618 (100.0%)
  register_spill_on_ccall:       482 ( 0.0%)
Top-10 side exit reasons (100.0% of total 22,245,731):
                  guard_shape_failure: 6,368,077 (28.6%)
                        compile_error: 5,883,100 (26.4%)
                      unhandled_splat: 3,799,787 (17.1%)
                      unhandled_kwarg: 3,599,863 (16.2%)
                   guard_type_failure: 1,574,419 ( 7.1%)
                   optional_arguments:   665,845 ( 3.0%)
                   unhandled_hir_insn:   209,530 ( 0.9%)
                  unhandled_yarv_insn:   144,434 ( 0.6%)
                           patchpoint:       633 ( 0.0%)
  block_param_proxy_not_iseq_or_ifunc:        43 ( 0.0%)
dynamic_send_count:    41,581,970
compiled_iseq_count:   372
failed_iseq_count:     39
compile_time:          882ms
profile_time:          4ms
gc_time:               19ms
invalidation_time:     0ms
vm_write_pc_count:     86,769,201
vm_write_sp_count:     86,382,095
vm_write_locals_count: 86,382,095
vm_write_stack_count:  86,382,095
code_region_bytes:     1,736,704
side_exit_count:       22,245,731
total_insn_count:      829,219,041
vm_insn_count:         371,028,505
zjit_insn_count:       458,190,536
ratio_in_zjit:         55.3%

Similarly in the lobsters benchmark, we have approximately 22% of the send_without_blocks as c functions.

***ZJIT: Printing ZJIT statistics on exit***
Top-5 dynamic send types (100.0% of total 75,599,723):
  send_without_block: 59,034,651 (78.1%)
                send: 10,683,350 (14.1%)
         invokesuper:  3,785,494 ( 5.0%)
         invokeblock:  1,253,723 ( 1.7%)
        send_forward:    842,505 ( 1.1%)
Top-6 send fallback def_types (100.0% of total 17,976,787):
      cfunc: 13,657,253 (76.0%)
    bmethod:  1,758,108 ( 9.8%)
  optimized:  1,655,647 ( 9.2%)
      alias:    725,436 ( 4.0%)
    attrset:    172,182 ( 1.0%)
       null:      8,161 ( 0.0%)
Top-9 unhandled YARV insns (100.0% of total 1,286,950):
         expandarray: 666,730 (51.8%)
        checkkeyword: 343,034 (26.7%)
    getclassvariable: 119,388 ( 9.3%)
  invokesuperforward:  81,667 ( 6.3%)
       getblockparam:  72,156 ( 5.6%)
   opt_duparray_send:   2,178 ( 0.2%)
         getconstant:   1,490 ( 0.1%)
          checkmatch:     288 ( 0.0%)
                once:      19 ( 0.0%)
Top-2 compile error reasons (100.0% of total 5,654,417):
  register_spill_on_alloc: 4,765,425 (84.3%)
  register_spill_on_ccall:   888,992 (15.7%)
Top-15 side exit reasons (100.0% of total 21,309,144):
                        compile_error: 5,654,417 (26.5%)
                   guard_type_failure: 4,297,033 (20.2%)
                  guard_shape_failure: 3,652,130 (17.1%)
                   optional_arguments: 3,320,762 (15.6%)
                  unhandled_yarv_insn: 1,286,950 ( 6.0%)
  block_param_proxy_not_iseq_or_ifunc: 1,055,487 ( 5.0%)
                      unhandled_kwarg:   688,709 ( 3.2%)
                unknown_newarray_send:   538,993 ( 2.5%)
                           patchpoint:   394,854 ( 1.9%)
                      unhandled_splat:   245,332 ( 1.2%)
                   unhandled_hir_insn:   147,357 ( 0.7%)
           block_param_proxy_modified:    26,322 ( 0.1%)
                            interrupt:       613 ( 0.0%)
               obj_to_string_fallback:       163 ( 0.0%)
               guard_type_not_failure:        22 ( 0.0%)
dynamic_send_count:    75,599,723
compiled_iseq_count:   4,879
failed_iseq_count:     380
compile_time:          8,722ms
profile_time:          62ms
gc_time:               37ms
invalidation_time:     257ms
vm_write_pc_count:     116,381,114
vm_write_sp_count:     114,278,889
vm_write_locals_count: 114,278,889
vm_write_stack_count:  114,278,889
code_region_bytes:     20,070,400
side_exit_count:       21,309,144
total_insn_count:      923,770,696
vm_insn_count:         311,766,771
zjit_insn_count:       612,003,925
ratio_in_zjit:         66.3%

Lastly, in railsbench, the figure is approximately 28%.

 ***ZJIT: Printing ZJIT statistics on exit***
Top-5 dynamic send types (100.0% of total 63,789,011):
  send_without_block: 50,272,421 (78.8%)
                send:  7,576,098 (11.9%)
         invokesuper:  4,109,163 ( 6.4%)
         invokeblock:  1,371,573 ( 2.2%)
        send_forward:    459,756 ( 0.7%)
Top-6 send fallback def_types (100.0% of total 18,949,525):
      cfunc: 14,908,448 (78.7%)
  optimized:  2,215,810 (11.7%)
    bmethod:  1,075,694 ( 5.7%)
      alias:    588,488 ( 3.1%)
    attrset:    121,143 ( 0.6%)
       null:     39,942 ( 0.2%)
Top-9 unhandled YARV insns (100.0% of total 1,424,506):
    getclassvariable: 381,573 (26.8%)
       getblockparam: 380,087 (26.7%)
        checkkeyword: 254,652 (17.9%)
  invokesuperforward: 199,443 (14.0%)
         expandarray: 168,577 (11.8%)
         getconstant:  39,994 ( 2.8%)
          checkmatch:     147 ( 0.0%)
                once:      19 ( 0.0%)
   opt_duparray_send:      14 ( 0.0%)
Top-2 compile error reasons (100.0% of total 3,718,544):
  register_spill_on_alloc: 2,932,100 (78.9%)
  register_spill_on_ccall:   786,444 (21.1%)
Top-14 side exit reasons (100.0% of total 11,707,715):
                        compile_error: 3,718,544 (31.8%)
                   optional_arguments: 2,483,449 (21.2%)
                  unhandled_yarv_insn: 1,424,506 (12.2%)
                  guard_shape_failure: 1,233,735 (10.5%)
                   guard_type_failure:   612,022 ( 5.2%)
  block_param_proxy_not_iseq_or_ifunc:   568,922 ( 4.9%)
                      unhandled_kwarg:   549,913 ( 4.7%)
                      unhandled_splat:   359,756 ( 3.1%)
                           patchpoint:   335,880 ( 2.9%)
                unknown_newarray_send:   257,458 ( 2.2%)
                   unhandled_hir_insn:   133,659 ( 1.1%)
           block_param_proxy_modified:    29,699 ( 0.3%)
               obj_to_string_fallback:       159 ( 0.0%)
                            interrupt:        13 ( 0.0%)
dynamic_send_count:    63,789,011
compiled_iseq_count:   2,545
failed_iseq_count:     207
compile_time:          4,369ms
profile_time:          25ms
gc_time:               66ms
invalidation_time:     10ms
vm_write_pc_count:     107,888,922
vm_write_sp_count:     105,284,435
vm_write_locals_count: 105,284,435
vm_write_stack_count:  105,284,435
code_region_bytes:     10,403,840
side_exit_count:       11,707,715
total_insn_count:      724,659,702
vm_insn_count:         203,095,167
zjit_insn_count:       521,564,535
ratio_in_zjit:         72.0%

Activity

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions