w3c / webrtc-rtptransport

Repository for the RTPTransport specification of the WebRTC Working Group
Other
18 stars 6 forks source link

BYOB interfaces to avoid ArrayBuffer churn #41

Closed tonyherre closed 3 months ago

tonyherre commented 4 months ago

Currently our APIs for reading out payload bytes & Header Extension bytes just pass an ArrayBuffer, but this requires new buffers to be allocated and GCed for every interaction, a cost which adds up at the frequencies & data volumes we're looking at. A bring-your-own-buffer approach would allow apps to maintain their own buffer pools, potentially even directly writing into a WASM memory block, thus avoiding another copy.

WebCodecs has taken this approach with all interfaces have a copyTo(AllowSharedBufferSource destination); method - eg see https://www.w3.org/TR/webcodecs/#ref-for-dom-encodedaudiochunk-copyto.

I suggest we follow this pattern for RTCRtpPacket.payload and RTCRtpHeaderExtension.value.

jesup commented 4 months ago

Makes a ton of sense, for similar reasons to WebCodecs

aboba commented 4 months ago

I agree.