-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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][mt] Update memory views after growth, refactor string processing, fix SharedArrayBuffer detection #86664
Conversation
…ffer from different JavaScript realm When performing tasks such as allocating or marshalling large amounts of memory in multithreaded .NET land, inconsistent and frequent crashing behavior is exhibited. Related issues: emscripten-core/emscripten#15217 https://github.com/dotnet/aspnetcore/issues/48390
@dotnet-policy-service agree |
Thanks for your contribution! If I understand correctly, this instanceof bug affects scenarios involving iframes because the iframe is a different realm and has its own builtins like Array and SharedArrayBuffer, right? So any case where we are using instanceof is potentially broken in that case, which is what motivates APIs like Array.isArray. |
Hi @kg! That's exactly the scenario I came across that motivated this fix. I'll get to work right away on a solution that avoids the call to I'm glad to help! |
… time avoiding call to Object.toString
Tagging subscribers to 'arch-wasm': @lewing Issue DetailsWhen performing tasks such as allocating or marshalling large amounts of memory in multithreaded .NET land, inconsistent and frequent crashing behavior is exhibited. I adapted a fix to this issue from this PR in the emscripten repository: Related issues:
|
@pavelsavara Please see the latest commit on my fork's I have not tried to see if my patch helps, as I have not built the runtime with the Hope this is helpful. Update: I don't know where in the code this corresponds to. If someone can point me to it so I can update the file with the same |
"memory pooling or reclamation mechanism that they use internally that causes buffers to cross the iframe boundary" could you please point me to more details about it ? |
Also, if there is buffer reuse across iframes, it should also manifest without threads, right ? @radekdoulik would we capture/notice the error if one of the AppStart measures failed to start the runtime in the iframe ? |
I get it now, in our benchmark it's not a |
main...IsaMorphic:runtime-wasmfix:broken-sample I will have look soon, probably next week. Thanks a lot! I would still love to read about how this is not a browser bug. :-D |
I processed further feedback from @kg about not calling While doing that I noticed that we have too many loops where we convert strings with different encodings, so I moved all of it into @ilonatommy I touched some of the hybrid locale stuff, please have look. There is bit of risk that this change will introduce perf regression, but it was that already yesterday. |
/azp run runtime-wasm |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run runtime-wasm |
Azure Pipelines successfully started running 1 pipeline(s). |
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.
Globalization pointer math checked.
/azp run runtime-wasm |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run runtime-wasm |
Azure Pipelines successfully started running 1 pipeline(s). |
I guess this is that we eliminated bunch of checks in the non-MT string conversion. |
"memory pooling or reclamation mechanism that they use internally that causes SharedArrayBuffer to cross the iframe boundary"
SharedArrayBuffer
viabuffer[Symbol.toStringTag] === "SharedArrayBuffer"
copyBufferIfNecessary
helperreceiveWorkerHeapViews
Module.HEAP
xx with newlocalHeapViewXXX()
receiveWorkerHeapViews
and produces updated short lived "local" view-s TEXTDECODER=0
emcc linker flag for MT buildModule.UTF8ArrayToString
andModule.UTF8ToString
with our ownutf8ToString
anddecodeUTF8
TextDecoder
for longer strings instead of emscripten byte-by-byte loopencodeUTF8
andutf8ToStringRelaxed
ofstrings.ts
HEAPU8
overHEAP8
for code consistencystring.ts
refactoringFixes #86696
Fixes #86642
Related issues:
emscripten-core/emscripten#15217