Repository navigation
perf(net): send ws binary messages without a Blob - #585
Open
0xmatthewb wants to merge 1 commit into
Open
0xmatthewb wants to merge 1 commit into
0xmatthewb wants to merge 1 commit into
Conversation
`start_send` wraps every `Message::Bytes` in a new `Blob` (ranile#502), and Chrome registers each Blob with the browser process. In Android Chrome profiles of a Nym mixnet client in a worker, which sends dozens of binary frames per second, creating and sending those Blobs takes 9-27% of the worker's busy time. `Uint8Array::from` already copies the bytes into a new, non-shared ArrayBuffer, so sending that view directly keeps the shared-memory fix from ranile#502 and drops the per-message Blob.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Since #502,
WebSocket::start_sendcopies eachMessage::Bytesinto aUint8Arrayand then wraps that copy in a newBlobbefore sending it. The copy is what makes sends work from shared wasm memory. The Blob contributes nothing to that fix, but Chrome registers every Blob with the browser process, so a client that sends binary frames continuously pays for one on every message. A Nym mixnet client in a Web Worker sends about 55 frames per second through this sink, and in V8 profiles of that worker on Android Chrome 145, creating and sending the Blobs took 9-27% of its busy time.This change sends the copied
Uint8Arraydirectly withsend_with_array_buffer_view. BecauseUint8Array::from(&[u8])goes through the copying typed-array constructor, the browser always receives a fresh, non-sharedArrayBuffer, so the #502 fix still holds. Message contents and boundaries, ordering relative to text messages, and theMessageSendErrormapping are unchanged.Validation
The gloo-net WebSocket tests pass in headless Chrome and Firefox, including
websocket_works, which round-trips aMessage::Bytes, and fmt and clippy are clean. On an Android Chrome 145 emulator, a Nym client built against this branch spends 2% of its worker's busy time on the send path, down from 27%.