Skip to content

Conversation

@kg
Copy link
Member

@kg kg commented Sep 5, 2024

This PR implements basic support for switches in the jiterpreter, with a configurable size limit (big ones would eat up all the available trace space) that can be set to 0 in order to disable them.

Switch targets that go backwards (Vlad says these should be exceedingly rare) will cause a runtime bailout, as will switches that are too big. In local testing these bailouts are very rare, even with the current low threshold.

If a switch targets places outside of the trace, only those switch targets that are outside will cause bailouts - the rest of them will still work. So even for large traces where half the switch arms aren't reachable, this is still an improvement over how it was before, I think.

In the future if we raise the max trace size we can also raise the size limit on switches - from looking at instrumentation, a limit of 64 or so is probably ideal.

This PR also fixes a bug I noticed - if the jiterpreter trace table filled up we were still generating+compiling a trace and then failing to put it into the table, which wasted CPU time.

Introduce runtime option for max switch size
Disable trace generation once the trace table fills up, since there's no point to it
@kg kg added arch-wasm WebAssembly architecture area-Codegen-Interpreter-mono labels Sep 5, 2024
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @BrzVlad, @kotlarmilos
See info in area-owners.md if you want to be subscribed.

@kg kg marked this pull request as ready for review September 5, 2024 22:16
@pavelsavara pavelsavara requested a review from BrzVlad September 6, 2024 09:57
Copy link
Member

@pavelsavara pavelsavara left a comment

Choose a reason for hiding this comment

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

@BrzVlad could you please review the logic please ?

mono_assert(getU16(ip) === MintOpcode.MINT_SWITCH, "decodeSwitch called on a non-switch");
const n = getArgU32(ip, 2);
const result = [];
/*
Copy link
Member

Choose a reason for hiding this comment

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

please remove dead code

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not dead code

@kg kg merged commit 5c4686f into dotnet:main Sep 7, 2024
jtschuster pushed a commit to jtschuster/runtime that referenced this pull request Sep 17, 2024
* Implement MINT_SWITCH opcode (without support for backward jumps)
* Introduce runtime option for max switch size (set to 0 to disable switches)
* Disable trace generation once the trace table fills up, since there's no point to it
sirntar pushed a commit to sirntar/runtime that referenced this pull request Sep 30, 2024
* Implement MINT_SWITCH opcode (without support for backward jumps)
* Introduce runtime option for max switch size (set to 0 to disable switches)
* Disable trace generation once the trace table fills up, since there's no point to it
@github-actions github-actions bot locked and limited conversation to collaborators Oct 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants