-
Couldn't load subscription status.
- Fork 5.2k
[browser] eager allocation of Promise/Task result for async JSImport/JSExport #95411
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
Conversation
|
Tagging subscribers to 'arch-wasm': @lewing Issue DetailsMotivationThis makes it possible to send marshaling "stack frame" of async This PR doesn't contain the MT changes which will use this. SummaryPR #93648 introduced virtual GC and JS handles. This PR optimizes it further by allocating the real This supports case target method synchronously returns null Changes
|
|
/azp run runtime-wasm |
|
Azure Pipelines successfully started running 1 pipeline(s). |
1310a12 to
78647a8
Compare
|
/azp run runtime-wasm |
|
Azure Pipelines successfully started running 1 pipeline(s). |
...ries/System.Runtime.InteropServices.JavaScript/System.Runtime.InteropServices.JavaScript.sln
Outdated
Show resolved
Hide resolved
...vices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSHostImplementation.Types.cs
Outdated
Show resolved
Hide resolved
...vices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSHostImplementation.Types.cs
Show resolved
Hide resolved
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.
Other than my comments I don't see anything blocking this, but I don't feel confident at all in my understanding of jsv/gcv vs js/gc handles or the correctness of the code using them
|
/azp run runtime-wasm |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
There is unrelated |
Motivation
"Because the caller already knows they need to create a proxy-promise, which would be later bound to result of the called function."
This makes it possible to send marshaling "stack frame" of async
JSImport/JSExportmethods as one-way message.Because
Promise/Taskresult is created by sender thread ahead of time and sending thread couldawaitit even before receiving thread saw the message.This PR doesn't contain the MT changes which will use this.
Summary
PR #93648 introduced virtual GC and JS handles.
They are good because we could allocate the handle to the future object of the other side, without crossing to that other side to create the real object. That matters in MT scenarios, in which we also need to cross to the correct thread.
This PR optimizes it further by allocating the real
PromiseHolderorTaskHolderand normal non-virtual handle for it.We do it for the return value of async
JSImportorJSExport.The
Task/Promisepassed as parameter keep using the virtual handles."Because we only need to pass virtual identity of the proxy-promise which will be created on the other side".
We still support case when target method returns synchronously resolved
Task/Promiseornull. Only when caller invokes theJSImport/JSExportsynchronously. Which is currently always.nullvalue and synchronous resolve/reject would not be possible return value of real async cross-thread MT dispatch. There are currently WS client scenarios which are using synchronousnullas signal. That would need to be fixed on another PR.Changes
PromiseHolderfor asyncJSImportinInvokeJSImportImplCreateJSOwnedHoldertoGetPromiseHoldergcvHandletogcHandlewhere both could be usedInvokeJSImpltoInvokeJSFunctionmono_wasm_invoke_bound_functiontomono_wasm_invoke_js_functionOwnerTIDinJSObjectinstead ofManagedThreadIdJSObject.DisposeasynchronouslyPosted to thread of affinity.