Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

st0012
Copy link
Member

@st0012 st0012 commented Sep 16, 2025

This reduces the dynamic_send_count in liquid-render by ~20%

Before

Top-4 dynamic send types (100.0% of total 37,691,693):
  send_without_block: 31,176,518 (82.7%)
                send:  6,207,698 (16.5%)
         invokeblock:    274,932 ( 0.7%)
         invokesuper:     32,545 ( 0.1%)
Top-4 send fallback def_types (100.0% of total 15,891,032):
      cfunc: 15,733,625 (99.0%)
  optimized:    144,322 ( 0.9%)
    attrset:     13,065 ( 0.1%)
      alias:         20 ( 0.0%)
dynamic_send_count:  37,691,693

After

Top-4 dynamic send types (100.0% of total 30,161,408):
  send_without_block: 23,358,749 (77.4%)
                send:  6,482,940 (21.5%)
         invokeblock:    286,934 ( 1.0%)
         invokesuper:     32,785 ( 0.1%)
Top-4 send fallback def_types (100.0% of total 7,411,863):
      cfunc: 7,248,096 (97.8%)
  optimized:   150,682 ( 2.0%)
    attrset:    13,065 ( 0.2%)
      alias:        20 ( 0.0%)
dynamic_send_count:  30,161,408

It adds a new CCallVariadic HIR for C methods with signature func(int argc, VALUE *argv, VALUE recv).
If my implementation is not too far off, I think we may be able to split it into few HIRs:

  • One for setting up frame
  • One for gen_push_opnds
  • CCall
  • One for gen_pop_opnds
  • One for clean up

Is this the direction we're expecting? 🤔
If that's the case, I prefer to merge the implementation with one HIR, and open an issue for the split as a todo.

This comment has been minimized.

@st0012 st0012 force-pushed the zjit-support-ccall-variadic branch 5 times, most recently from d5b8b93 to b884653 Compare September 17, 2025 20:15
@st0012 st0012 force-pushed the zjit-support-ccall-variadic branch 2 times, most recently from ed7068e to aa5b153 Compare September 17, 2025 20:56
@st0012 st0012 marked this pull request as ready for review September 17, 2025 20:57
@matzbot matzbot requested a review from a team September 17, 2025 20:57
@st0012 st0012 force-pushed the zjit-support-ccall-variadic branch from aa5b153 to 30b288d Compare September 17, 2025 21:09
@k0kubun
Copy link
Member

k0kubun commented Sep 17, 2025

I guess we're missing some deoptimization for C calls?

https://github.com/ruby/ruby/actions/runs/17810760232/job/50633769374?pr=14575

    1) Failure:
  TestRubyOptimization#test_trace_optimized_methods [/home/runner/work/ruby/ruby/src/test/ruby/test_optimization.rb:242]:
  [ruby-core:87638].
  <[:-@,
   :max,
   :min,
   :+,
   :-,
   :*,
   :/,
   :%,
   :==,
   :<,
   :<=,
   :>,
   :>=,
   :<<,
   :&,
   :|,
   :[],
   :[]=,
   :length,
   :empty?,
   :nil?,
   :succ,
   :!,
   :=~]> expected but was
  <[:-@,
   :+,
   :-,
   :*,
   :/,
   :%,
   :==,
   :<,
   :<=,
   :>,
   :>=,
   :<<,
   :&,
   :|,
   :[],
   :[]=,
   :length,
   :empty?,
   :nil?,
   :succ,
   :!,
   :=~]>.

Are we doing something similar to YJIT's if c_method_tracing_currently_enabled(jit) check and record_global_inval_patch(asm, CodegenGlobals::get_outline_full_cfunc_return_pos())?

@st0012
Copy link
Member Author

st0012 commented Sep 17, 2025

Looks like I need to bail the codegen when TracePoint events c_call or c_return is enabled. I'll see how I can pass ec in to call rb_c_method_tracing_currently_enabled

@st0012 st0012 force-pushed the zjit-support-ccall-variadic branch 2 times, most recently from d7b0979 to cc4728a Compare September 18, 2025 08:10
@st0012 st0012 force-pushed the zjit-support-ccall-variadic branch 2 times, most recently from bb95274 to 1db3946 Compare September 18, 2025 17:12
@st0012 st0012 force-pushed the zjit-support-ccall-variadic branch from 1db3946 to 91e8687 Compare September 18, 2025 17:42
@st0012
Copy link
Member Author

st0012 commented Sep 18, 2025

@tekknolagi I think this is ready to merge

@tekknolagi tekknolagi merged commit 797a411 into ruby:master Sep 18, 2025
85 checks passed
@tekknolagi tekknolagi deleted the zjit-support-ccall-variadic branch September 18, 2025 18:46
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