-
Notifications
You must be signed in to change notification settings - Fork 5k
[wasm] Introduce jiterpreter control flow pass #83247
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
Conversation
Tagging subscribers to 'arch-wasm': @lewing Issue DetailsThis PR introduces a control flow graph (CFG) pass to the jiterpreter that runs after the initial code generation pass. Things that are currently generated inline like branch target blocks and branches are now recorded in a list of segments, and in a second pass all the segments are stitched together with the necessary webassembly flow control logic inserted inbetween. This allows turning forward branches into direct jumps and turns backward branches into a direct jump paired with a table dispatch. It is theoretically possible to avoid the table dispatch for backward branches, but I'm not smart enough to figure out how to do it in a general way :-) This should provide large speedups for traces that contain many branch targets, since right now we pay the cost of an eip check for each branch target. The cfg is able to omit all of those checks. For traces containing backward branches the existence of the dispatch table means we still have overhead there, but it's not as bad. This will probably regress startup time slightly (as visible in the Page Show timing, though I think that is probably noise) due to the second pass and the overhead in tracking segments, but it's possible to optimize that. Initial browser-bench measurements, compared vs main:
|
Generate fallthrough in CFG Generate branch block header partially in cfg Emit branches in CFG Checkpoint: Emit loop and exit return in CFG (broken) Fix CFG emitting function header in the wrong place Improve accuracy of cfg size estimation Remove log messages Checkpoint: Forward branches partially working Fix non-conditional branches not being added to target table Remove fallthrough
33dd63a
to
17cca49
Compare
Use copyWithin to implement appendBytes where possible More accurate overhead calculation
This PR introduces a control flow graph (CFG) pass to the jiterpreter that runs after the initial code generation pass. Things that are currently generated inline like branch target blocks and branches are now recorded in a list of segments, and in a second pass all the segments are stitched together with the necessary webassembly flow control logic inserted inbetween. This allows turning forward branches into direct jumps and turns backward branches into a direct jump paired with a table dispatch. It is theoretically possible to avoid the table dispatch for backward branches, but I'm not smart enough to figure out how to do it in a general way :-)
This should provide large speedups for traces that contain many branch targets, since right now we pay the cost of an eip check for each branch target. The cfg is able to omit all of those checks. For traces containing backward branches the existence of the dispatch table means we still have overhead there, but it's not as bad.
This will probably regress startup time slightly (as visible in the Page Show timing, though I think that is probably noise) due to the second pass and the overhead in tracking segments, but it's possible to optimize that.
Initial browser-bench measurements, compared vs main: