Skip to content

Commit

Permalink
Disable jiterp safepoints in single-threaded WASM (#99558)
Browse files Browse the repository at this point in the history
Safepoints don't do anything in single threaded wasm, so the jiterp can just not generate any code for them. This should address part of a performance regression in #99554
  • Loading branch information
kg authored Mar 12, 2024
1 parent 1e2fdb5 commit 6cb660d
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/mono/browser/runtime/jiterpreter-support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1246,12 +1246,14 @@ class Cfg {
this.overheadBytes += 11;
}

// Account for the size of the safepoint
if (
(branchType === CfgBranchType.SafepointConditional) ||
(branchType === CfgBranchType.SafepointUnconditional)
) {
this.overheadBytes += 17;
if (WasmEnableThreads) {
// Account for the size of the safepoint
if (
(branchType === CfgBranchType.SafepointConditional) ||
(branchType === CfgBranchType.SafepointUnconditional)
) {
this.overheadBytes += 17;
}
}
}

Expand Down Expand Up @@ -1505,6 +1507,9 @@ export const _now = (globalThis.performance && globalThis.performance.now)
let scratchBuffer: NativePointer = <any>0;

export function append_safepoint(builder: WasmBuilder, ip: MintOpcodePtr) {
// safepoints are never triggered in a single-threaded build
if (!WasmEnableThreads)
return;
// Check whether a safepoint is required
builder.ptr_const(cwraps.mono_jiterp_get_polling_required_address());
builder.appendU8(WasmOpcode.i32_load);
Expand Down

0 comments on commit 6cb660d

Please sign in to comment.