-
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
[browser] eager allocation of Promise/Task result for async JSImport/JSExport #95411
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
/JSExport
methods as one-way message.Because
Promise
/Task
result is created by sender thread ahead of time and sending thread couldawait
it 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
PromiseHolder
orTaskHolder
and normal non-virtual handle for it.We do it for the return value of async
JSImport
orJSExport
.The
Task
/Promise
passed 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
/Promise
ornull
. Only when caller invokes theJSImport
/JSExport
synchronously. Which is currently always.null
value 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 synchronousnull
as signal. That would need to be fixed on another PR.Changes
PromiseHolder
for asyncJSImport
inInvokeJSImportImpl
CreateJSOwnedHolder
toGetPromiseHolder
gcvHandle
togcHandle
where both could be usedInvokeJSImpl
toInvokeJSFunction
mono_wasm_invoke_bound_function
tomono_wasm_invoke_js_function
OwnerTID
inJSObject
instead ofManagedThreadId
JSObject.Dispose
asynchronouslyPost
ed to thread of affinity.