-
Notifications
You must be signed in to change notification settings - Fork 164
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
Garbage-free streaming fetch into a WebAssembly (Shared)ArrayBuffer? #1057
Comments
While your code does not construct extra typed array views, the stream itself definitely does. Every Moreover, the With a BYOB reader, you construct a new
I doubt you can eliminate all garbage collection, and I don't think that should be a goal. Even if you were to eliminate the typed arrays by making the API closer to something like C++'s Trying to get rid of all these small objects would make the API much harder to use, since you'd have to get rid of a lot of useful abstractions like typed arrays and promises. I'd argue that this would feel "alien" for most JavaScript developers. |
At least in Chrome, our goal is not to eliminate GC but to use generational GC so that as long as there is only a small number of short-lived objects generated, you won't see any GC pauses. You can track the progress of this effort here: https://bugs.chromium.org/p/chromium/issues/detail?id=1029379. The streams standard creates lots of short-lived promises internally. It's theoretically possible to eliminate those promises for platform-generated streams, but in practice we don't because it would add a lot of complexity to the implementation. Instead we rely on the lower-level GC to be efficient. I don't know about other browsers, but I suspect they are also working on ways of letting JavaScript interface with WebAssembly while avoiding GC pauses from temporary objects. |
See also #757 |
Thanks for the replies. The reasoning makes sense, although expecting lower-level GC to be efficient is a lost battle for Wasm real-time rendering applications. Fortunately pages will not need to download data all the time, so any stuttering will be limited to periods of data download, so I suppose the API convenience/simplicity will be worth it. |
Looking at the BYOB reading example at https://streams.spec.whatwg.org/#example-manual-read-bytes , the code looks awkward because of the large number of JS garbage that is generated. High performance animation-heavy WebAssembly applications strive to operate garbage-free, because JS GC pressure is known to generate microstuttering in WebGL rendering/animation.
Would it be possible to create an API that would enable garbage-free streaming into a(n) (Shared)ArrayBuffer?
The BYOB example on the page looks like
The stream avoids extra copy, but generates garbage. Comparing to a non-BYOB variant for a fetch:
This code does not generate excessive typed array views, but it has an extra memory copy.
I wonder if there would be a way to get to a JS GC free + zero copy way of downloading files?
The text was updated successfully, but these errors were encountered: