Open Bug 2095447 Opened 8 days ago Updated 4 days ago

WebTransport datagrams.createWritable() write(): avoid copying the payload more than once

Categories

(Core :: DOM: Networking, enhancement, P3)

enhancement

Tracking

()

People

(Reporter: jesup, Assigned: jesup)

References

Details

(Whiteboard: [necko-triaged])

OutgoingDatagramStreamAlgorithms::WriteCallbackImpl() copies every written BufferSource into an nsTArray<uint8_t> before it has decided what to do with it (writeDatagrams step 5, done early because the code was ordered around step 4). That copy is wasted when the datagram is then dropped: larger than outgoingMaxDatagramSize (step 4), or the transport already cleaned up. The payload is then moved into an OutgoingDatagram, batched for the next OutgoingDatagrams IPC message, and serialized into the message, which copies it again.

For small-datagram workloads (the xpcshell perftest in dom/webtransport/test/xpcshell/test_datagram_perf.js) this is per-datagram allocation and memcpy on the content process main thread.

Ideas, roughly in order of effort:

  • Check the byte length against OutgoingMaxDatagramSize before copying, so the dropped cases copy nothing.
  • Copy straight into the pending batch (or a shared-memory/IPC buffer) instead of into an intermediate nsTArray that the batch then moves and serializes.
  • Measure first with the perftest to see whether it is significant.

Raised in review of D338152 (bug 2085588) by kagami

Severity: -- → S4
Priority: -- → P3
Whiteboard: [necko-triaged]
You need to log in before you can comment on or make changes to this bug.