runtime: wasm GC causes stop the world for a very long time #54444
Labels
arch-wasm
WebAssembly issues
compiler/runtime
Issues related to the Go compiler and/or runtime.
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Performance
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I am working on a hobby game engine that has both Native (OpenGL) and WASM (WebGL2) support.
When running a larger scene in WebAssembly I notice that whenever a GC is triggered it causes everything to freeze for about a second or more.
Actually, it happens with smaller scenes too but just less often (due to GC triggering less often). I think that the duration of the freeze is proportional to the number of active pointer references but this needs more testing to verify.
I try not to allocate much memory but it happens that once a frame I might allocate a few KBs here and there (I have a custom react-style Go UI framework that is hard to make allocation-free due to tree invalidation logic and besides, one should be able to make use of Go's memory management). This means that after 15s-60s everything just freezes.
I managed to write a dummy program that reproduces the issue:
What did you expect to see?
Smooth and consistent logging in the Browser Console.
What did you see instead?
A stop the world situation once in a while (every 2 seconds or so). The
Total
counter (indicating the number of GC runs) always increases immediatelly after the freeze, showing that it is related to GC.What's interesting is that none of the stats (even the frame time) indicate that GC took more time than indicated but the fact is that the Browser freezes. Could it be that Go is doing something that JS or the Browser does not like and needs to adjust to once setInterval callback has completed (e.g. memory shuffling or something of the kind)?
This is reproducible with both Chrome and Firefox. Have not tried other browsers.
The text was updated successfully, but these errors were encountered: