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

Skip to content

ZJIT: Compile opt_new to slow-path SendWithoutBlock #13216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 30, 2025

Conversation

tekknolagi
Copy link
Contributor

The optimizer will be able to handle this differently than the
interpreter; we will use type information to rewrite SendWithoutBlock
:new on any Class that doesn't override :new into the split
alloc+:initialize form.

The optimizer will be able to handle this differently than the
interpreter; we will use type information to rewrite SendWithoutBlock
:new on any Class that doesn't override :new into the split
alloc+:initialize form.
@matzbot matzbot requested a review from a team April 30, 2025 19:56
@tekknolagi
Copy link
Contributor Author

A question I have for the future: how hard is it to synthesize a CALL_DATA? If we're going to be turning this call to :new into a call to :initialize, the call to :initialize has to come from somewhere. I suppose we could try and keep track of the optimized "inlined" :initialize call from the opt_new compiler output, but that seems brittle. We'll probably also want to do more of this kind of stuff in the future unrelated to what's in the bytecode.

@k0kubun
Copy link
Member

k0kubun commented Apr 30, 2025

A question I have for the future: how hard is it to synthesize a CALL_DATA? If we're going to be turning this call to :new into a call to :initialize, the call to :initialize has to come from somewhere. I suppose we could try and keep track of the optimized "inlined" :initialize call from the opt_new compiler output, but that seems brittle.

You'll need to discover an existing cc in the ISEQ to avoid extra allocation, and the same applies to ci when it has keyword arguments. And the cd itself should also be fetched from the bytecode to avoid consuming extra memory. Basically, we should not synthesize a cd but just discover it since the ISEQ already has one and we don't want to waste memory for JIT.

Since the bytecode has send instructions that call into .new and #initialize, we'll need to discover those instructions. I'm not sure what kind of algorithm we need to discover them, but if it's too hard, we could modify the interpreter to let the interpreter and ZJIT agree on where to find the instructions.

@k0kubun k0kubun merged commit 73fdd90 into ruby:master Apr 30, 2025
83 of 86 checks passed
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.

2 participants