Shopify/yjit

Documentation to understand exit reasons and act on them?

Closed this issue · 3 comments

Hi, when running some code with --yjit-stats I get output such as

method call exit reasons: 
                   block_arg      38055 (52.3%)
               iseq_has_rest      32452 (44.6%)
                 send_getter       1165 ( 1.6%)
    iseq_missing_optional_kw        713 ( 1.0%)
       cfunc_ruby_array_varg        330 ( 0.5%)
         args_splat_non_iseq         44 ( 0.1%)
invokeblock exit reasons: 
                proc      19777 (99.7%)
    iseq_tag_changed         53 ( 0.3%)
invokesuper exit reasons: 
    block         60 (100.0%)
leave exit reasons: 
        interp_return   57593965 (100.0%)
    start_pc_non_zero        398 ( 0.0%)
         se_interrupt         56 ( 0.0%)
getblockparamproxy exit reasons: 
    (all relevant counters are zero)
getinstancevariable exit reasons:
    megamorphic          3 (100.0%)
setinstancevariable exit reasons:
    (all relevant counters are zero)
opt_aref exit reasons: 
    (all relevant counters are zero)
expandarray exit reasons: 
    rhs_too_small      15930 (100.0%)
opt_getinlinecache exit reasons: 
    (all relevant counters are zero)
invalidation reasons: 
    constant_state_bump         88 (68.8%)
       constant_ic_fill         22 (17.2%)
          method_lookup         18 (14.1%)

Do you have plans to document the exit reasons printed by YJIT stats with actionable suggestions, so people could optimize their code to make it better perform with yjit? Or are we still too early in development to make this feasible and should just refer to the general performance tips given in https://github.com/ruby/ruby/blob/master/doc/yjit/yjit.md#performance-tips?

Hi @Aqualon

We do change the code fairly frequently. Eventually the hope is to have as few exits as possible, but if you paste the full output you get from --yjit-stats I can try to give you some feedback.

Thanks for the offer @maximecb. I'm still in the beginning of trying out yjit with our apps, so probably you can spend your time for more important things. Just wondered if --yjit-stats is something for regular ruby devs out there or more a tool for the ones working on yjit and ruby itself and asked the question 😄

eregon commented

Just wondered if --yjit-stats is something for regular ruby devs out there or more a tool for the ones working on yjit and ruby itself and asked the question

The latter. I try to clarify that in ruby/ruby#7139. I would advise against changing your code based on some details of a JIT, JITs change, and the changed code might soon do worst than it ever helped. For instance I expect with time YJIT will have less and less side exits, and working around them could easily prove counter-productive.
Profiling your code and looking at it for obvious inefficiencies is usually a much better approach.