Investigate effect of the switchToWasmInstanceRealm
Categories
(Core :: JavaScript: WebAssembly, enhancement, P3)
Tracking
()
People
(Reporter: yury, Unassigned)
References
(Blocks 1 open bug)
Details
We are doing realm switching in wasm call. In most of the cases it is not needed. Change JSContext::realm_ so that it’s always null when in wasm functions:
- This will let us remove switchToWasmInstanceRealm()
https://searchfox.org/mozilla-central/source/js/src/jit/MacroAssembler.cpp#2046 - Wasm generated code never uses the realm, so we can lazily set it when leaving wasm code
- The following places will need to be updated
a) Instance::callExport
- clear JSContext::realm_ to null calling into wasm
- Reset it back on returning from wasm
b) Instance::callImport
- set JSContext::realm_ to Instance::realm_ before calling import
- Clear it to null when returning to wasm
c) GenerateJITEntry/GenerateImportJITExit
- Not sure what these need yet (bug 1810891)
d) Some of the Instance builtins (Instance::structNew) will need the JSContext::realm_ set
- Can add a RAII class ‘AutoWasmBuiltin’ which sets realm for while the builtin is called
That will let us change direct (and indirect) calls so that they always reload the pinned registers after a call -- remove slow/fast callsites.
How slow it will be?
| Reporter | ||
Comment 1•2 years ago
|
||
After trying to move code around, I found just removing fast callsites causes and adding a flags to the frame to have a conditional code to restore realm and pinned registers causes the performance regression at most 25%.
The JSContext::realm_ is tightly connected with how we are testing stuff, during debugging, returning (multi-value) or passing values (such as BigInt64) to imports. We also do some asserts in debug mode when profiling scripts are set. So it is less complicated to keep JSContext::realm_ in-sync with current instance.
If we can speculate that none of our imports (functions or wasm instances) will be changing the realm, removing real switch code will give us at most 3% gain in the performance.
FWIW the effects of changes are only visible on embenchen tests. Running the changes on sightglass gives inconclusive results.
Updated•2 years ago
|
Comment 2•10 months ago
|
||
We have investigated this now.
Description
•