-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Optimize (WasmRoot|WasmExternalRoot).clear #77521
Conversation
Tagging subscribers to 'arch-wasm': @lewing Issue Details
This PR also optimizes the root Before:
After:
JSImportTaskFail improved considerably due to the Note that these tests have significant timing variance from run to run because they spend a lot of time in the JS and C# garbage collectors (mostly due to the string allocations) This fixes #77473
|
Looks like using the class syntax to override |
This comment was marked as outdated.
This comment was marked as outdated.
Adding a test is a good idea, yours looks like it should also benchmark fine. The defineProperty is expensive, though. |
This approach to optimizing ManagedError can't work because of a chrome bug: https://bugs.chromium.org/p/chromium/issues/detail?id=1379185 |
src/mono/wasm/runtime/roots.ts
Outdated
const destinationAddress = this.__buffer.get_address(this.__index); | ||
cwraps.mono_wasm_write_managed_pointer_unsafe(destinationAddress, <ManagedPointer>value); | ||
if (value === <any>0) { | ||
// Don't use .set since it involves a gc write barrier, and the write barrier |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we concerned only about the case when the root is just newly allocated?
Or this is also when somebody free the root ?
Do you mean that it doesn't matter that GC on another thread would hold the root a bit longer ?
What is the semantics of clear
method ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clear zeroes out a root after you're done with it. This happens both when freeing the root (to avoid leaking object references) and when done with a reusable scratch root. The most common example of something where this would happen a lot is the root we use to store return values from function calls.
I suggest that you revert the |
2330716
to
9b40657
Compare
Rebased and updated to remove the error stuff @pavelsavara |
…y barrier when zeroing a root for improved interop perf
4fc70b8
to
8a986c1
Compare
This PR optimizes the wasm root
clear
andset
methods to not use a write barrier when zeroing a root, because the write barrier is expensive and not really necessary. The downside is this could cause an object to live slightly too long in some cases, but we callclear
a LOT for correctness so the cost has a significant impact on interop speed, at least according to browser-bench.Before:
After:
This optimization improves the legacy export performance since we use a root to store the return value. String stuff uses roots too, as do some of the other JS wrappers and such.
Note that these tests have significant timing variance from run to run because they spend a lot of time in the JS and C# garbage collectors (mostly due to the string allocations)