Skip to content
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

Zero copy support via BYOB (add an example) #131

Closed
aboba opened this issue Aug 25, 2020 · 13 comments · Fixed by #584
Closed

Zero copy support via BYOB (add an example) #131

aboba opened this issue Aug 25, 2020 · 13 comments · Fixed by #584
Assignees
Labels
Editorial This is an editorial PR that can be merged by editors without discussion PR exists A PR exists for this issue

Comments

@aboba
Copy link
Collaborator

aboba commented Aug 25, 2020

QUIC implementations such as quant support zero-copy (via warpcore). Via BYOB, zero-copy should be feasible for both readable and writable streams.

So it seems to me that zero-copy should be feasible in WebTransport via BYOB, in which case some examples should be provided to show how it works.

@DavidSchinazi
Copy link

Can you clarify what data exactly should not be copied and when? Our QUIC implementation lives in a different process from where JavaScript runs, so a copy will be necessary for security reasons.

@yutakahirano
Copy link
Contributor

yutakahirano commented Aug 31, 2020

With Chromium implementation BYOB doesn't reduce copy but it does reduce the number of allocations, pressure for the GC system and the peak memory usage.

The allocation CPU cost is real, from our experience in WebSocket.

@aboba
Copy link
Collaborator Author

aboba commented Sep 1, 2020

Going over the current state of browser implementations, a WebTransport application using WebAssembly and Workers may require as many as a dozen memory copies on both the sending and receiving side. There are copies for send and receive (C++/JS), for use of WebAssembly, as well as for use of data within a Transferrable Stream.

@yutakahirano
Copy link
Contributor

Could you elaborate on a bit more please? We, the Streams API team in Google, want to help people write efficient applications by providing good APIs and implementation. cc:@ricea @domenic

@aboba
Copy link
Collaborator Author

aboba commented Sep 3, 2020

One of the scenarios for WebTransport + WebCodecs is realtime communications in which portions of the pipeline (such as packetization or machine learning) are handled in WebAssembly. Currently, it appears that copies may exist at every stage in the pipeline (e.g. capture, machine learning, encode, packetization, send, receive, de-packetization, decode, more machine learning, render). Several of these copies represent additional overhead not present in WebRTC (e.g. no additional copies for packetization/de-packetization). This isn't solely a WebTransport problem; some of these copies are being worked on (support for zero-copy capture and zero-copy rasterization), some are due to WASM.

@jan-ivar jan-ivar changed the title Zero copy support Zero copy support via BYOB Jun 9, 2021
@yutakahirano yutakahirano added this to the No mileston milestone Jun 30, 2021
@aboba
Copy link
Collaborator Author

aboba commented Sep 19, 2022

Is BYOB supported currently? If I try below code in Chromium, last line produces an error.

const reader = transport.incomingUnidirectionalStreams.getReader();
const {value, done } = await reader.read();
const byob_reader = value.getReader({mode: "byob"});

If it is supported, is there a running sample code?

@jianjunz
Copy link
Member

BYOB support for WebTransport streams was merged just 10 days ago.

https://chromium-review.googlesource.com/c/chromium/src/+/3799089

@aboba
Copy link
Collaborator Author

aboba commented Sep 20, 2022

Thanks! Will check it out in Canary.

@aboba
Copy link
Collaborator Author

aboba commented Sep 21, 2022

@jianjunz Trying it out in M108, seems to be working very well. Overall latency is down quite a bit. Thank you!

@jianjunz
Copy link
Member

Thanks for your feedback. BYOB support for datagrams (CL) is not merged yet. One concern from Adam is it will lose the datagram boundaries. Feel free to add your comments if you have. Thanks.

@jan-ivar
Copy link
Member

The streams spec has a byob example we might want to crib.

@aboba
Copy link
Collaborator Author

aboba commented Jan 25, 2023

I have included BYOB for streams in the WebCodecs Echo sample (requires M108+).

@jan-ivar
Copy link
Member

Once #487 is merged, we have BYOB for both datagrams and regular streams. So now's a good time to add some examples to show how it works.

@jan-ivar jan-ivar changed the title Zero copy support via BYOB Zero copy support via BYOB (add an example) Oct 18, 2023
@nidhijaju nidhijaju self-assigned this Oct 26, 2023
@jan-ivar jan-ivar added the Editorial This is an editorial PR that can be merged by editors without discussion label Jan 24, 2024
@nidhijaju nidhijaju added PR exists A PR exists for this issue and removed Ready for PR labels Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Editorial This is an editorial PR that can be merged by editors without discussion PR exists A PR exists for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants