Skip to content

Conversation

@goshanraj-g
Copy link

Fixes #829

Instead of calling rb_ary_new_capa and rb_ary_push for each element (this is N+1 C function calls), this uses gen_push_opnds and calls rb_ec_ary_new_from_values once, which matches what the interpreter and YJIT do

gen_prepare_leaf_call_with_gc(asm, state);

let length: c_long = elements.len().try_into().expect("Unable to fit length of elements into c_long");
gen_prepare_non_leaf_call(jit, asm, state);

Choose a reason for hiding this comment

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

Why non-leaf call?

Copy link
Author

Choose a reason for hiding this comment

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

Sorry about that! I'll change it to a leaf call (gen_prepare_leaf_call_with_gc). I was referencing the hash insertion functions which were similar and utilized non-leaf calls. Now, the updated code uses leaf calls (submitted a PR to ruby/ruby)

@tekknolagi tekknolagi changed the title ZJIT: Optimize NewArray to use rb_ec_ary_new_from_values (fixes #829) ZJIT: Optimize NewArray to use rb_ec_ary_new_from_values Dec 3, 2025
@tekknolagi
Copy link

FYI you should make a PR against ruby/ruby instead

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: Write elements to an array at once on Insn::NewArray

2 participants