Repository navigation
perf: don't allocate in UDP send path - #3948
larseggert wants to merge 2 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3948 +/- ##
==========================================
- Coverage 96.73% 96.62% -0.12%
==========================================
Files 113 118 +5
Lines 43493 43922 +429
Branches 43493 43922 +429
==========================================
+ Hits 42074 42440 +366
- Misses 1407 1461 +54
- Partials 12 21 +9
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Merging this PR will regress 1 benchmark1 warning
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing |
c132a3c to
6a481e5
Compare
😱 |
|
Yeah, the mix of regressions and improvements is odd |
d87f784 to
b86aba5
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The public owned-output conversion must enforce single-datagram batches in release builds.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Reworks UDP output to reuse caller-owned buffers, reducing send-path allocations across transport, HTTP/3, and binaries.
Changes:
- Makes datagram batches borrow reusable send buffers.
- Threads buffers through transport and HTTP/3 output paths.
- Adds buffer reuse, PMTUD, batching, and saved-datagram tests.
File summaries
| File | Description |
|---|---|
neqo-udp/src/lib.rs |
Updates send/receive buffers and borrowed batches. |
neqo-transport/tests/server.rs |
Updates server tests and saved-input coverage. |
neqo-transport/tests/connection.rs |
Adapts connection and encoder tests. |
neqo-transport/src/server.rs |
Writes server output into caller buffers. |
neqo-transport/src/path.rs |
Builds batches over borrowed payloads. |
neqo-transport/src/packet/mod.rs |
Writes version negotiation into supplied buffers. |
neqo-transport/src/lib.rs |
Exports batch metadata. |
neqo-transport/src/connection/tests/pmtud.rs |
Tests PMTUD send-buffer sizing. |
neqo-transport/src/connection/tests/mod.rs |
Tests reuse and batch bounds. |
neqo-transport/src/connection/tests/keys.rs |
Tests cleanup after key errors. |
neqo-transport/src/connection/mod.rs |
Implements reusable-buffer output batching. |
neqo-http3/tests/connect_udp.rs |
Adapts proxy packet exchange. |
neqo-http3/src/server.rs |
Threads buffers through HTTP/3 server output. |
neqo-http3/src/connection_client.rs |
Threads buffers through HTTP/3 client output. |
neqo-http3/src/buffered_send_stream.rs |
Uses generalized encoder construction. |
neqo-common/src/datagram.rs |
Converts batches to borrowed buffer views. |
neqo-common/src/codec.rs |
Generalizes buffer and encoder handling. |
neqo-bin/src/udp.rs |
Accepts borrowed batches for sending. |
neqo-bin/src/server/mod.rs |
Adds a persistent server send buffer. |
neqo-bin/src/server/http3.rs |
Passes buffers through HTTP/3 server adapter. |
neqo-bin/src/server/http09.rs |
Passes buffers through HTTP/0.9 server adapter. |
neqo-bin/src/lib.rs |
Creates pre-sized reusable send buffers. |
neqo-bin/src/client/mod.rs |
Adds a persistent client send buffer. |
neqo-bin/src/client/http3.rs |
Passes buffers through HTTP/3 client adapter. |
neqo-bin/src/client/http09.rs |
Passes buffers through HTTP/0.9 client adapter. |
Review details
- Files reviewed: 25/25 changed files
- Comments generated: 2
- Review effort level: Balanced (auto)
Note
Copilot is running an experiment and ran this review at Balanced.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
Borrowing the caller's buffer instead of owning it (vs #2747) is clearly the better trade: one non-generic output path, no monomorphisation blowup, and Encoder::new + the blanket impl<B: Buffer> Buffer for &mut B are a nice simplification on their own. The Batch<'a>/OutputBatch<'a> plumbing reads cleanly and the new tests hit the interesting invariants (error leaves the buffer empty, reuse across connections, PMTUD probe sizing).
Two things beyond the inline comments:
The meta() → rebuild() dance is the main architectural risk. It exists purely to end the borrow, and it works by re-deriving the batch from (src, dst, tos, datagram_size) plus all of the buffer. That silently encodes two unwritten invariants: a producer that returns no batch must leave the buffer empty, and a batch must start at offset 0. Both hold today, but only by inspection of every process_input/handle_initial/process_multiple_output path, and nothing catches a future violation outside of the one debug_assert!(!buffer.is_empty()). A SendBuf newtype that hands out a written window (fn finish(&mut self, range) -> Batch<'_>) — or having rebuild take the byte range alongside the metadata — would make this checked rather than commented. Worth considering before this shape spreads further.
The upload regression is still unexplained. @martinthomson flagged transfer/1-conn/1-100mb-req/mtu-1504 at +67.8%, and the reply only notes the mix is odd. For a PR whose sole justification is allocation removal in the send path, that wants a resolution (or an explicit "CodSpeed noise, here's the walltime data") before merge. One thing I'd check: send_buffer.reserve(first_datagram) is a no-op for the long-lived buffer but forces a full-MTU (up to probe-size) allocation on every Output::owned call, so the single-datagram API now allocates ~plpmtu where it previously grew geometrically to the actual packet size.
Minor: this is a breaking change for downstream (neqo_glue) beyond the signature churn — OutputBatch/datagram::Batch gain a lifetime and lose Clone, and TryFrom<Batch> for Datagram, From<Datagram> for Batch and Encoder::new_borrowed_vec are gone. Presumably intended, but it needs a coordinated mozilla-central patch.
b86aba5 to
46b5343
Compare
There was a problem hiding this comment.
Borrowing the caller's buffer instead of owning it is the right call — one lifetime parameter and zero new generics in the output path, against the two buffer types and six monomorphised copies in #2747. Encoder::new + the blanket impl<B: Buffer> Buffer for &mut B are a nice simplification on their own, and SendBuf mirroring RecvBuf keeps the page-residency trick out of embedders. The invariant tests (exhausted_write_keys_leave_send_buffer_empty, shared_send_buffer_across_connections, send_buffer_holds_pmtud_probe, saved_datagrams_are_drained) are well chosen — they test the new contract rather than the refactor.
Resolved from my previous pass: the SendBuf newtype with 0xff pre-touch, the truncate in Output::owned, the VN debug_assert!(send_buffer.is_empty()), and assert_eq!(bounded.num_datagrams(), 2). On @Copilot's Output::owned comment: the truncate does make release and debug agree on safety, but a >1-datagram batch is now silently reduced to its first segment rather than rejected as TryFrom did — fine given owned fixes max_datagrams to 1, worth knowing if it ever grows another caller.
Architecturally, the one thing I'd push on: correctness now rests on an unwritten "the buffer contains exactly one batch, starting at offset 0" invariant that spans neqo-transport → neqo-http3 → embedders, enforced only by debug_assert!s at each producer. rebuild reconstructs the extent from buffer.len(), so any violation is a wrong segment_size/length pair passed to sendmsg in release builds. Carrying the batch length in BatchMeta and having rebuild slice &mut buffer[..len] would make that structural instead of asserted, and would let rebuild stop caring where in the buffer the batch sits.
Two smaller things:
- Breaking public API.
Connection::process_multiple_output/process_multiple,Server::process_multiple{,_input},Http3Client::process_multiple_output,Http3Server::process_multiple,Path::datagram_batch, plus removal ofEncoder::new_borrowed_vec,TryFrom<Batch> for Datagram,From<Datagram> for Batch, andCloneonBatch/OutputBatch. Worth calling out in the PR description so theneqo_glueside lands together. - Scope. The
RecvBufchange (Vec<Vec<u8>>→ one contiguousBox<[u8]>,RECV_BUF_SIZE65535 → 65536) is a receive-path change in a send-path PR, and its stated motivation only bites whereNUM_BUFS > 1, i.e. Apple. Splitting it out would let it be benchmarked on its own.
Finally, since the framing is "vs #2747, the code bloat that regressed streams*": the streams*/Download numbers for this version aren't in the description. Given no bench calls process_multiple_output directly, those numbers are the only evidence the borrow actually recovers the regression — worth pasting them in.
7560a59 to
c7bed43
Compare
There was a problem hiding this comment.
Borrowing rather than owning is the right call here, and it shows: one non-generic &mut Vec<u8> threaded down, BatchMeta as the "borrow ends here" hinge, and a batch bounded by max_datagrams instead of buffer capacity. The send_buffer.clear() discipline (clear on entry to process_multiple_output/process_multiple_input, clear on error in output_dgram_batch_on_path) plus the debug_assert!(send_buffer.is_empty()) at each offset-0 producer (batch loop, VN, Retry) is the load-bearing invariant, and it now looks consistently asserted at every producer I could find. Cursor::truncate's zero-fill makes Batch::copy_from's partial-write undo genuinely observable, which batch_copy_from_too_small pins nicely.
All feedback from the previous round is addressed: SendBuf newtype in neqo-udp with SEND_BUF_SIZE private, BatchMeta as a named struct in neqo-common, the Output::owned truncate (also answering Copilot's release-vs-debug point), offset-0 assertions at VN and Retry, the rebuild contract doc, version_negotiation moved to impl<B: Buffer> with a # Panics section, the corrected page-residency doc wording, and assert_eq!(bounded.num_datagrams(), 2).
Architectural notes that span the PR:
- Breaking surface for
neqo_glue.datagram::Batch<'a>/OutputBatch<'a>gain a lifetime and loseClone; everyprocess_multiple*grows a parameter;From<Datagram> for Batch,TryFrom<Batch> for DatagramandEncoder::new_borrowed_vecare gone;packet::Builder::version_negotiationchanges shape. Worth calling out in the commit message and landing with the mozilla-central side ready. The lifetime in particular means an embedder can no longer queue output — anything that wants to defer a batch past the nextprocess_*call has to copy it out.neqo-binis fine (the buffer is aRunnerfield held across the writableawait), but it's a real constraint to state in theOutputBatchdocs. RecvBuf/RECV_BUF_SIZEis orthogonal. The 65535→65536 stride and theVec<Vec<u8>>→Box<[u8]>collapse are a receive-path change riding along in a send-path PR. Given two CodSpeed regressions are still outstanding against seven improvements, splitting it into its own commit would make the numbers bisectable — and it's a change worth its own scrutiny, since it turns 16 independent 64 KiB allocations into one contiguous 1 MiB one.SEND_BUF_SIZEand the search table are coupled but unlinked. 65535 is exactly the bound (the loop admits a datagram only whileaddress_family_max_mtu - position >= mtu, soposition <= 65535), andaddress_family_max_mtu()is the search-table top.neqo-udpcan'tconst_assertagainstneqo-transport, so raisingMTU_SIZES_V*would silently reintroduce a realloc. The doc comment onSEND_BUF_SIZEgets this right; a pointer in the other direction (a comment atMTU_SIZES_V4) would close the loop.- Benchmarks.
streams*regressing was the stated reason for this alternative to #2747 — worth confirming explicitly that those are clean now, and that the two remaining CodSpeed regressions aren't in that family, especially given the "different runtime environments" caveat on that report and the local run showing ~7% on both upload and download.
c7bed43 to
4131ccd
Compare
There was a problem hiding this comment.
Borrowing the caller's buffer instead of owning it is clearly the better of the two designs: one non-generic output path, no available()/copy_into scaffolding, and max_datagrams rather than buffer capacity bounding the batch. I re-verified the invariants that hold it together and they do hold at this head: Connection::process_multiple_output/Server::process_multiple_input clear on entry, output_dgram_on_path writes nothing net when it returns SendOption::No (because Encoder::new records start), so the num_datagrams == 0 early return really does leave an empty buffer, and SEND_BUF_SIZE == 65535 is exactly the bound the batch loop enforces (address_family_max_mtu - position < mtu, with address_family_max_mtu the top of the PMTUD search table). Also good: the packet.version().expect(...) on the server input path is now a non-panicking is_none_or.
Resolved since the last review round: BatchMeta as a named struct in neqo-common, the SendBuf newtype with AsMut only (and SEND_BUF_SIZE private), the offset-0 debug_assert!s at both the VN and Retry producers, the single path borrow in the batch prologue, reserve-vs-capacity assertion in send_buffer_holds_pmtud_probe, exact num_datagrams() in max_datagrams_bounds_batch, the release-mode truncate in Output::owned, the version_negotiation panic doc, and the stray BuilderOffsets Clone.
Two earlier points are still open (not re-raised inline): Output::owned is unconditionally pub with its one-datagram contract enforced only by a debug_assert_eq! in single() (also raised by Copilot), and Connection::process_multiple_output's doc still does not name the 65535 capacity an embedder needs to never reallocate — which matters because neqo_udp::SendBuf is unreachable from neqo-transport alone.
Architectural notes:
rebuildspans the whole buffer. Correctness now rests on "the buffer holds exactly this batch" being maintained acrossneqo-transport,neqo-http3and embedders, enforced by four scattereddebug_assert!s plus two "same offset-0 invariant as VN" comments. Carrying the batch length inBatchMetaand slicing inrebuild(&mut buffer[start..start + len]) would make it correct by construction, delete every one of those asserts, and let producers append rather than having to start at zero. Worth considering before this contract reachesneqo_glue.- Public API breaks for mozilla-central.
OutputBatchgains a lifetime and losesClone;process_multiple{,_output,_input}gain a parameter;datagram::Batch::newtakes&mut [u8];From<Datagram> for Batch,TryFrom<Batch> for Datagram,From<Output> for OutputBatchandEncoder::new_borrowed_vecare gone. A companionneqo_gluepatch will be needed; the description is the right place to say which buffer lifetime you expect it to adopt. - Scope. The
RecvBufrework (Vec<Vec<u8>>→ oneBox<[u8]>, stride 65535 → 65536) is a receive-path change in a send-path PR and is independently arguable; splitting it would make both bisectable. - Follow-up.
handle_initial/accept_connectionstill hardcodeNonZeroUsize::MIN, so a server's first flight is one datagram per call even though the caller's buffer is now sized for a whole batch. Threadingmax_datagramsdown throughprocess_inputlooks mechanical and is the obvious next win. - Numbers. Since #2747 was dropped over a
streams*regression, please put themain-vs-branch benchmark deltas in the description — that is the load-bearing claim here.
4131ccd to
b6fd996
Compare
There was a problem hiding this comment.
Borrowing the caller's buffer is clearly the better of the two designs: one non-generic buffer type (&mut Vec<u8>) travels the whole output path, the blanket impl<B: Buffer> Buffer for &mut B removes the duplicated Vec/&mut Vec impls, and Encoder::new replaces new_borrowed_vec. Net negative diff with the allocation gone from output_dgram_batch_on_path.
Three PR-wide observations, none repeated inline:
-
Porting cost for embedders. This is a broad public-API break that
neqo_gluehas to absorb in lockstep:OutputBatch<'a>/datagram::Batch<'a>gain a lifetime and loseClone,Batch::newtakes&mut [u8],From<Datagram> for BatchandTryFrom<Batch> for Datagramare gone,Encoder::new_borrowed_vecis renamed, andConnection::process_multiple{,_output},Server::process_multiple{,_input},Http3Client::process_multiple_outputandHttp3Server::process_multipleall gain a parameter. Worth a line in the release notes so the gecko-side patch is obvious. -
The 65535 in
neqo-udpis an untested cross-crate invariant.SEND_BUF_SIZEis only correct becausepmtud's search table tops out at 65535 and the batch loop bounds itself byaddress_family_max_mtu; nothing fails if a future table entry breaks that, and the consequence is a realloc of a 64 KiB buffer on the hot send path.gso_with_max_mtualready drives PLPMTU to the 65507 maximum with a sharedsend_buffer— anassert!(send_buffer.capacity() <= u16::MAX as usize)after its loop would pin it for the price of one line. -
Scope. The
RecvBufrework (16 separate 64 KiBVecs → one 1 MiBBox<[u8]>, stride 65535 → 65536) is a receive-path change in a send-path PR, and it is independently benchmarkable —NUM_BUFSis 1 off Apple, where the page-alignment argument in the doc comment does not apply at all. Splitting it out would make a bisect of any futureDownload/streams*movement unambiguous.
Resolved since my earlier reviews: the BatchMeta named struct, the SendBuf newtype with AsMut, truncate in Output::owned, the rebuild contract plus its datagram_size <= buffer.len() assert, the offset-0 assertions at both the VN and Retry producers, version_negotiation moved to impl<B: Buffer> with an accurate # Panics, the single path borrow in the batch prologue, the copy_from error message, and the max_datagrams/PMTUD-probe test tightening. A few earlier comments are still open (Output::owned visibility, reserve for the whole batch, the process_multiple_input doc); not restating them here.
There was a problem hiding this comment.
Re-review of the borrowing approach vs. #2747. The overall shape — Batch<'a> borrowing a caller-owned Vec<u8>, BatchMeta/rebuild to break the borrow across layers, Output::owned to keep the single-datagram APIs owning — reads well and the −91 lines vs. an owning batch is convincing. I verified the two soundness questions I had: Buffer::as_mut for Cursor<&mut [u8]> returns only ..position, so Batch::copy_from's &mut buffer.as_mut()[start..] really is just the written bytes; and SEND_BUF_SIZE (65535) does bound a batch, since output_dgram_batch_on_path breaks once address_family_max_mtu - position < mtu and the search-table top is 65535 — so the pre-touched SendBuf never reallocs.
Only one new inline comment this round.
Resolved since my last review: the SendBuf newtype now lives in neqo-udp (with AsMut rather than DerefMut, and the Deref impl dropped); vec![0xff; _] instead of alloc_zeroed; BatchMeta is a named struct; version_negotiation moved to impl<B: Buffer> Builder<B>; the path prologue is a single RefCell borrow; max_datagrams_bounds_batch asserts exactly 2; and send_buffer_holds_pmtud_probe now asserts capacity from an empty Vec.
Still open, not re-raised inline: the release-mode truncation in Output::owned/single, rebuild spanning the whole buffer, the offset-0 coupling between copy_from/VN and rebuild, NonZeroUsize::new(vn_len)? after save_for_later, reserve(first_datagram) for a multi-datagram loop, the RecvBuf "doubles the pages" wording, BuilderOffsets: Clone, and the incomplete # Errors on copy_from.
Architectural notes for the PR as a whole:
- Public API break for embedders.
OutputBatchgains a lifetime,Connection::process_multiple_output/process_multiple,Server::process_multiple{,_input},Http3Server::process_multipleandHttp3Client::process_multiple_outputall gain a&mut Vec<u8>, anddatagram::BatchlosesClone,From<Datagram>andTryFrom<Batch> for Datagram.neqo_glueneeds a matching change; worth calling out in the commit message so the Gecko-side uplift isn't a surprise. - The buffer contract is a documented invariant, not a type. Three separate
debug_assert!(send_buffer.is_empty())sites plus "buffermust hold exactly the batchmetadescribes" is a lot of invariant for a plain&mut Vec<u8>. ASendBuf-style newtype inneqo-commonthat ownsclear()/position()and hands outrebuildas a method would make the offset-0 requirement unrepresentable-if-violated, and would also giveneqo_gluethe page-residency behaviour for free instead of re-deriving it. Worth considering as a follow-up rather than blocking this. - No benchmark in the diff. The motivating claim is the
streams*regression in #2747; aneqo-binbench delta (or a note of one) in the PR description would make the "borrowing beats owning" argument reproducible for reviewers.
There was a problem hiding this comment.
Borrowing the caller's buffer rather than owning it is the right call over #2747: one non-generic datagram::Batch<'a>, no monomorphisation blow-up in the output path, and max_datagrams rather than buffer capacity bounding the batch. The Buffer for &mut B blanket impl and the Encoder::new collapse are nice DRY wins on their own. A few PR-wide observations, none repeated inline:
Where the win actually lands. Only process_multiple* callers benefit; process_output/process/Server::process still allocate a fresh Vec per call via Output::owned. mozilla-central's neqo_glue needs the SendBuf plumbing before any of this shows up in Firefox, so it'd be good to say in the description which side of that line the streams*/transfer* numbers were measured on, and to post before/after for the regression #2747 caused.
Scope. The RecvBuf rework (Vec<Vec<u8>> → Box<[u8]>, RECV_BUF_SIZE 65535 → 65536) is a receive-path change with its own independent rationale and its own perf claim, in a PR titled "don't allocate in UDP send path". It would be easier to bisect and to measure as a separate PR.
Downstream API breaks worth calling out in the description for neqo_glue and other embedders: OutputBatch gains a lifetime; TryFrom<OutputBatch> for Output, From<Output> for OutputBatch, TryFrom<Batch> for Datagram, From<Datagram> for Batch, Batch: Clone and Encoder::new_borrowed_vec are gone; Batch::new, Path::datagram_batch and packet::Builder::version_negotiation change signature. BatchMeta is also now reachable via two public paths (neqo_common::datagram and neqo_transport).
Resolved since my last pass (thanks): the unused Deref import, SendBuf's Deref/AsRef impls replaced by AsMut, the alloc_zeroed pre-touch, the five path borrows in the batch prologue collapsed to one, version_negotiation moved to impl<B: Buffer>, and both weak test assertions (max_datagrams_bounds_batch, send_buffer_holds_pmtud_probe) tightened.
Still open from that pass, not re-raised inline: the release-mode single-datagram invariant in OutputBatch::single/Output::owned and rebuild's whole-buffer span; the public BatchMeta 4-tuple with adjacent SocketAddrs; Server::process_multiple_input silently clearing a caller-owned buffer; the NonZeroUsize::new(vn_len)? after save_for_later; NonZeroUsize::MIN for the server's first flight vs. the 3× anti-amplification allowance (RFC 9000 §8.1); and shared_send_buffer_across_connections never actually handing a dirty buffer to a connection that writes.
Responding to @Copilot's note on Output::owned: the send_buffer.truncate(meta.datagram_size.get()) added since does bound the release-mode damage — a multi-datagram batch now loses the trailing segments instead of being emitted as one oversized Datagram, so it is no longer a protocol-visible bug. Silently dropping segments is still a worse contract than the TryFrom error it replaced, though, and owned is pub, so a non-debug_assert check there is still warranted.
One correction to my inline note on pmtud.rs:218: SEARCH_TABLE_LEN is private to crate::pmtud, so use a literal bound (or export it) rather than the identifier in that snippet.
Performance profiles for profiler.firefox.comBenchmarks (14)
|
There was a problem hiding this comment.
Borrowing the caller's buffer instead of owning it is the right call — the generic blast radius of #2747 is gone, datagram::Batch<'a> stays non-generic, and the blanket impl<B: Buffer> Buffer for &mut B plus a single Encoder::new are genuine DRY wins on their own.
Soundness of the buffer reuse. The scheme rests on two invariants, and both hold non-accidentally, which is worth recording in the code rather than only debug_assert!ing:
- Offset 0.
output_dgram_on_pathreturnsSendOption::Noexactly whenencoder.is_empty()(mod.rs#L2980), andEncoder::newanchorsstartatposition(), so "no datagram produced" ⟹ nothing appended. Combined with the unconditionalclear()on entry toprocess_multiple_outputand theinspect_errclear, everyprocess_inputpath that returnsNoneprovably leaves the buffer empty — so the VN/Retry producers really do start at 0. - No cross-peer bleed.
BatchMetacarrieslenandfrom_metaslices&mut d[..meta.len], so a stale suffix from a previous connection can never be segmented into a batch. This is the part that would have been a real leak hadrebuildspanned the whole buffer; good that it doesn't.
Encapsulation. The batch → meta → rebuild round trip now appears at five call sites (Server::process_multiple_input ×2, process_next_output, Server::process_multiple, Http3Server::process_multiple), each with a "Metadata only, so the borrow ends here" comment. That is the borrow checker showing through the API. It may not be avoidable without polonius, but it is the main readability cost of this approach versus #2747, and OutputBatch::{meta, rebuild} + Batch::{meta, from_meta} is four public entry points for one operation.
Scope of the win. Output::owned allocates a fresh Vec per call, so process_output/process are byte-for-byte as allocating as on main. Everything in-tree except the two neqo-bin runners uses those — test_fixture's simulator and all of neqo-transport/benches included — so transfer*/send_streams won't move, and neqo_glue gets nothing until it migrates to process_multiple_* with a persistent buffer. Worth saying so in the PR description, and confirming the coordinated glue patch exists.
Breaking public API (for the Firefox uplift): OutputBatch<'a> gains a lifetime; datagram::Batch is no longer owning or Clone; From<Datagram> for Batch and TryFrom<Batch> for Datagram are gone; Encoder::new_borrowed_vec → Encoder::new; and five entry points gain a required send_buffer parameter.
Resolved since my earlier rounds: Batch::new's empty guard, single()'s unconditional assert with truncate(meta.len), BatchMeta as a named struct in neqo-common re-exported from lib.rs, version_negotiation returning Encoder::len(), Retry writing bytes directly (retiring copy_from/available/copy_output_into), the SendBuf newtype over AsMut, rebuild's # Panics, qtrace! regaining the payload, None::<Datagram>, the exact num_datagrams() assertions, the bounded PMTUD warm-up, BuilderOffsets: Clone, and — now that reserve is gone — the Output::owned capacity regression. Moving NonZeroUsize::new(vn_len)? ahead of save_for_later also closes the saved_datagrams desync.
Still open from earlier rounds, not re-raised inline: Output::owned being pub, pmtud::SEARCH_TABLE_LEN being pub on a private module, the undocumented clear-first contract on Server::process_multiple_input, the unreachable send_buffer.clear() before Error::Internal, shared_send_buffer_across_connections never letting a second sender write into the dirty buffer, the .dgram().unwrap() in the PMTUD warm-up loop, a const_assert! pinning SEND_BUF_SIZE to the top of the search table, and the duplicated invalid_dgram closure in tests/server.rs.
mxinden
left a comment
There was a problem hiding this comment.
Much simpler than my initial patch. Thanks.
I will need some more time to review. But in favor of merging this.
(Past me has spend a lot of time on this, thus glad if we can finally get rid of the temporary send buffer.)
a067ee7 to
a24d672
Compare
There was a problem hiding this comment.
I checked the latest head, a24d672, against the full review history and found no new defects, so I didn't post any inline comments. It matches the code the previous round (at a067ee7) already cleared. Batch::from_meta now requires meta.len to match the buffer length exactly. That still holds for every caller of OutputBatch::rebuild, because each one clears the buffer and writes its batch from offset 0. I didn't run the separate code-review skill pass.
|
@mxinden I minimized the diff to main a bit by keeping cold paths (VN, etc.) as-is. |
There was a problem hiding this comment.
Checked the head commit against the code-review pass and the full review history. Nothing new turned up, so I'm writing no review. I found no new defects at head daf3bd2, so I'm leaving no inline comments. The code-review pass raised points that either repeat earlier threads or describe a failure no current caller can hit.
martinthomson
left a comment
There was a problem hiding this comment.
As indicated, we're going to try out an option where the connection holds the buffer. That means that we can't share buffers between connections, but these aren't very big.
There was a problem hiding this comment.
🟡 Changes recommended
Batch reconstruction can panic for supported short datagrams and for writes to nonempty buffers because metadata validation rejects short payloads and write appends bytes without accounting for existing contents.
2 open issues
2 resolved since last review
Review effort: Balanced
26624da to
c10c97b
Compare
|
@martinthomson this is now with your idea. |
Client/server transfer resultsPerformance differences relative to 261eb33. Transfer of 33554432 bytes over loopback, min. 100 runs. All unit-less numbers are in milliseconds.
Table above only shows statistically significant changes. See all results below. All resultsTransfer of 33554432 bytes over loopback, min. 100 runs. All unit-less numbers are in milliseconds.
Download data for |
Benchmark resultsSignificant performance differences relative to 261eb33. transfer/1-conn/1-100mb-req (aka. Upload)/mtu-1500: 💚 Performance has improved by -6.4701%. time: [57.710 ms 57.766 ms 59.358 ms]
baseline: [61.315 ms 61.762 ms 62.013 ms]
change:
time: [-6.5615% -6.4701% -3.8929%] (p = 0.01 < 0.05)
Performance has improved.transfer/1-conn/1-100mb-resp (aka. Download)/mtu-1500: 💚 Performance has improved by -7.6888%. time: [56.810 ms 56.980 ms 57.387 ms]
baseline: [61.653 ms 61.726 ms 62.129 ms]
change:
time: [-7.9637% -7.6888% -7.0292%] (p = 0.01 < 0.05)
Performance has improved.streams-flow-controlled/walltime/1-streams/each-4194304-bytes: 💚 Performance has improved by -3.4878%. time: [12.767 ms 12.782 ms 12.842 ms]
baseline: [13.240 ms 13.244 ms 13.306 ms]
change:
time: [-3.6037% -3.4878% -3.0345%] (p = 0.01 < 0.05)
Performance has improved.streams-flow-controlled/walltime/10-streams/each-1048576-bytes: 💚 Performance has improved by -3.5260%. time: [34.753 ms 34.981 ms 35.007 ms]
baseline: [36.132 ms 36.259 ms 36.348 ms]
change:
time: [-4.1541% -3.5260% -3.4546%] (p = 0.01 < 0.05)
Performance has improved.All resultstransfer/1-conn/1-100mb-req (aka. Upload)/mtu-1500: 💚 Performance has improved by -6.4701%. time: [57.710 ms 57.766 ms 59.358 ms]
baseline: [61.315 ms 61.762 ms 62.013 ms]
change:
time: [-6.5615% -6.4701% -3.8929%] (p = 0.01 < 0.05)
Performance has improved.transfer/1-conn/1-100mb-resp (aka. Download)/mtu-1500: 💚 Performance has improved by -7.6888%. time: [56.810 ms 56.980 ms 57.387 ms]
baseline: [61.653 ms 61.726 ms 62.129 ms]
change:
time: [-7.9637% -7.6888% -7.0292%] (p = 0.01 < 0.05)
Performance has improved.transfer/1-conn/1-1b-resp (aka. HPS)/mtu-1500: No change in performance detected. time: [3.7788 ms 3.7910 ms 3.8067 ms]
baseline: [3.7911 ms 3.7973 ms 3.8071 ms]
change:
time: [-0.4879% -0.1652% +0.2461%] (p = 0.15 > 0.05)
No change in performance detected.transfer/1-conn/10_000-parallel-1b-resp (aka. RPS)/mtu-1500: No change in performance detected. time: [87.223 ms 87.768 ms 88.056 ms]
baseline: [87.395 ms 88.303 ms 88.629 ms]
change:
time: [-1.2233% -0.6057% -0.2799%] (p = 0.10 > 0.05)
No change in performance detected.streams-flow-controlled/walltime/1-streams/each-4194304-bytes: 💚 Performance has improved by -3.4878%. time: [12.767 ms 12.782 ms 12.842 ms]
baseline: [13.240 ms 13.244 ms 13.306 ms]
change:
time: [-3.6037% -3.4878% -3.0345%] (p = 0.01 < 0.05)
Performance has improved.streams-flow-controlled/walltime/10-streams/each-1048576-bytes: 💚 Performance has improved by -3.5260%. time: [34.753 ms 34.981 ms 35.007 ms]
baseline: [36.132 ms 36.259 ms 36.348 ms]
change:
time: [-4.1541% -3.5260% -3.4546%] (p = 0.01 < 0.05)
Performance has improved.streams/walltime/1-streams/each-1000-bytes: Change within noise threshold. time: [151.39 µs 151.61 µs 151.91 µs]
baseline: [152.89 µs 153.15 µs 153.88 µs]
change:
time: [-1.1541% -1.0106% -0.8115%] (p = 0.01 < 0.05)
Change within noise threshold.streams/walltime/1000-streams/each-1-bytes: No change in performance detected. time: [4.7242 ms 4.7331 ms 4.7347 ms]
baseline: [4.6996 ms 4.7110 ms 4.7325 ms]
change:
time: [+0.2783% +0.4676% +0.5020%] (p = 0.06 > 0.05)
No change in performance detected.streams/walltime/1000-streams/each-1000-bytes: Change within noise threshold. time: [15.276 ms 15.290 ms 15.327 ms]
baseline: [15.341 ms 15.375 ms 15.410 ms]
change:
time: [-0.6430% -0.5523% -0.3099%] (p = 0.01 < 0.05)
Change within noise threshold.transfer/walltime/pacing-false/same-seed: No change in performance detected. time: [3.1205 ms 3.1243 ms 3.1291 ms]
baseline: [3.1183 ms 3.1222 ms 3.1275 ms]
change:
time: [-0.0560% +0.0659% +0.2187%] (p = 0.55 > 0.05)
No change in performance detected.transfer/walltime/pacing-false/varying-seeds: Change within noise threshold. time: [3.1299 ms 3.1359 ms 3.1443 ms]
baseline: [3.1505 ms 3.1551 ms 3.1647 ms]
change:
time: [-0.7989% -0.6076% -0.3419%] (p = 0.01 < 0.05)
Change within noise threshold.transfer/walltime/pacing-true/same-seed: No change in performance detected. time: [3.6008 ms 3.6116 ms 3.6253 ms]
baseline: [3.5994 ms 3.6160 ms 3.6281 ms]
change:
time: [-0.4225% -0.1226% +0.2555%] (p = 1.00 > 0.05)
No change in performance detected.transfer/walltime/pacing-true/varying-seeds: No change in performance detected. time: [3.6085 ms 3.6154 ms 3.6195 ms]
baseline: [3.6056 ms 3.6277 ms 3.6322 ms]
change:
time: [-0.5311% -0.3389% -0.2259%] (p = 0.15 > 0.05)
No change in performance detected.Instructions per cycle
All benchmarks
Profiles for profiler.firefox.com (64)
Download data for |
Failed Interop TestsQUIC Interop Runner, client vs. server, differences relative to
All resultsSucceeded Interop TestsQUIC Interop Runner, client vs. server neqo-pr as client
neqo-pr as server
Unsupported Interop TestsQUIC Interop Runner, client vs. server neqo-pr as client
neqo-pr as server
|
|
@mxinden @martinthomson: This is about as minimal a change I can make this. |



Let callers hand a sent batch's buffer back, so building the next batch reuses it instead of allocating.
Alternative to #2747.