Skip to content

Commit

Permalink
Optimize (WasmRoot|WasmExternalRoot).clear (#77521)
Browse files Browse the repository at this point in the history
Optimize (WasmRoot|WasmExternalRoot).clear to not use a memory barrier when zeroing a root for improved interop perf
  • Loading branch information
kg authored Nov 8, 2022
1 parent f33badf commit 86611ab
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/mono/wasm/runtime/roots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,10 @@ class WasmJsOwnedRoot<T extends MonoObject> implements WasmRoot<T> {
}

clear(): void {
this.set(<any>0);
// .set performs an expensive write barrier, and that is not necessary in most cases
// for clear since clearing a root cannot cause new objects to survive a GC
const address32 = this.__buffer.get_address_32(this.__index);
Module.HEAPU32[address32] = 0;
}

release(): void {
Expand Down Expand Up @@ -420,7 +423,9 @@ class WasmExternalRoot<T extends MonoObject> implements WasmRoot<T> {
}

clear(): void {
this.set(<any>0);
// .set performs an expensive write barrier, and that is not necessary in most cases
// for clear since clearing a root cannot cause new objects to survive a GC
Module.HEAPU32[<any>this.__external_address >>> 2] = 0;
}

release(): void {
Expand All @@ -432,4 +437,4 @@ class WasmExternalRoot<T extends MonoObject> implements WasmRoot<T> {
toString(): string {
return `[external root @${this.address}]`;
}
}
}

0 comments on commit 86611ab

Please sign in to comment.