-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
perf: remove an unnecessary buffer copy from WASM asset loading pipeline #22310
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
base: main
Are you sure you want to change the base?
Conversation
andriyDev
left a comment
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.
I am a big fan of getting rid of these copies!! Thank you!
The use of unsafe is a little uncomfy, but it's a pretty obvious optimization and avoids assigning a bunch of zeroes for no reason.
|
The generated |
andriyDev
left a comment
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.
Approving though this is of course blocked on the git dependency.
Objective
The current asset loading pipeline on WASM looks like this:
fetchweb API.ArrayBuffer, and make a JSUInt8Arrayview into it.Vec<u8>and copy the contents of the JS Uint8Array into it.VecReader, which implementsAsyncRead..read_to_end()on the type-erased VecReader to copy the bytes into another Vec.Step (3.) above is unnecessary, as we can read from the
Uint8Arraydirectly.Solution
Add a new
UInt8ArrayReadertype, which wraps a JS byte buffer to implementAsyncRead.read_to_end()for this type, I had to forkstackfutureto add support for non-send futures.NOTE: before we can merge this PR, we will either have to wait until the following
stackfuturePR is merged, or publish a fork: microsoft/stackfuture#34Testing
many_foxesexample as a smoke test, which did not appear to have any problems.0.15.3release, for the WASM app at my workplace.AsyncSeekfunctionality -- as far as I can tell this functionality is not used by any of ourAssetLoaders.