Skip to content
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

[wasm] Implement the ENDFINALLY opcode in the jiterpreter #84273

Merged
merged 4 commits into from Apr 5, 2023

Conversation

kg
Copy link
Contributor

@kg kg commented Apr 3, 2023

By marking the opcode following each CALL_HANDLER opcode as a back-branch target, we can then generate a conditional backwards branch in the jiterpreter for ENDFINALLY opcodes and allow traces to keep executing after a finally block. This should improve performance for traces containing try/finally, especially ones that have it inside of a loop body. I added a simple browser-bench measurement that shows a measurable improvement (950usec -> 700usec) from this.

Currently the support is limited for methods with at most three CALL_HANDLER opcodes, because the codegen for the ENDFINALLY will get too bloated beyond that.

One risk to this is that now more traces will contain backwards branches than before, which results in them having a dispatch loop at entry.

This PR also tweaks the CFG to generate fewer entries in the backward branch dispatcher in some cases, which helps compensate for the new targets introduced by finally support.

@kg kg added arch-wasm WebAssembly architecture area-Codegen-Jiterpreter-mono labels Apr 3, 2023
@ghost ghost assigned kg Apr 3, 2023
@ghost
Copy link

ghost commented Apr 3, 2023

Tagging subscribers to 'arch-wasm': @lewing
See info in area-owners.md if you want to be subscribed.

Issue Details

By marking the opcode following each CALL_HANDLER opcode as a back-branch target, we can then generate a conditional backwards branch in the jiterpreter for ENDFINALLY opcodes and allow traces to keep executing after a finally block. This should improve performance for traces containing try/finally, especially ones that have it inside of a loop body.

Currently the support is limited for methods with at most three CALL_HANDLER opcodes, because the codegen for the ENDFINALLY will get too bloated beyond that.

One risk to this is that now more traces will contain backwards branches than before, which results in them having a dispatch loop at entry.

Author: kg
Assignees: -
Labels:

arch-wasm, area-Codegen-Jiterpreter-mono

Milestone: -

kg added 2 commits April 4, 2023 15:08
Logging cleanup
Don't generate dispatch entries for back branches we haven't seen targeted
Add browser-bench measurement for try-finally
@kg kg marked this pull request as ready for review April 4, 2023 23:39
@kg kg merged commit 66211eb into dotnet:main Apr 5, 2023
94 of 101 checks passed
@ghost ghost locked as resolved and limited conversation to collaborators May 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-wasm WebAssembly architecture
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants