Skip to content

perf(transport): pre-size datagram batch buffer - #4042

Closed
codspeed[bot] wants to merge 1 commit into
mainfrom
codspeed/optim-datagram-batch-buffer
Closed

codspeed[bot] wants to merge 1 commit into
mainfrom
codspeed/optim-datagram-batch-buffer

Conversation

@codspeed

@codspeed codspeed Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Summary

Pre-size the send buffer in Connection::output_dgram_batch_on_path to the smaller of max_datagrams * plpmtu and the address-family MTU limit. This avoids repeated growth and copying while encoding a datagram batch, including the AEAD expansion and GSO cases. PMTUD probes can still grow the buffer when needed.

Validation

  • cargo +nightly fmt --all -- --check passed.
  • cargo check --locked --package neqo-transport --all-targets passed.
  • cargo test --locked --package neqo-transport passed: 965 unit tests plus integration suites.
  • cargo test --locked --workspace --exclude mtu passed.
  • The full workspace command was also attempted; its seven mtu network-namespace tests fail in this sandbox because the required netns/interface setup is unavailable. These tests are unrelated to this change.

CodSpeed

Compared on the same dedicated macro runner using transfer_walltime:

  • walltime/pacing-false/varying-seeds: +4.32%
  • walltime/pacing-false/same-seed: +3.47%
  • walltime/pacing-true/varying-seeds: +2.59%
  • walltime/pacing-true/same-seed: unchanged within noise

The comparison reports 3 improvements, 1 unchanged benchmark, and no regressions. View the CodSpeed comparison.

A matched local transfer_simulated comparison was non-regressing but within the simulation noise threshold; the macro-runner walltime result is the validation used here.

@larseggert

Copy link
Copy Markdown
Collaborator

@codspeedbot check the existing PRs, don't we have an equivalent PR open?

@codspeed

codspeed Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

@codspeedbot check the existing PRs, don't we have an equivalent PR open?

Yes. #3948 (perf: don't allocate in UDP send path, an alternative to the draft #2747) already does what this PR does, and does more.

  • This PR (perf(transport): pre-size datagram batch buffer #4042): keeps let mut send_buffer = Vec::new() in output_dgram_batch_on_path and only pre-sizes it, so there's still one heap allocation per batch.
  • perf: don't allocate in UDP send path #3948: removes that local Vec completely. output_dgram_batch_on_path takes a caller-owned send_buffer: &mut Vec<u8> that the client, server and neqo-transport server reuse across calls. Once the first batch has been sent, the buffer already has enough capacity, so it doesn't need to grow or be allocated again. Pre-sizing no longer helps there.

Both PRs change the same lines in neqo-transport/src/connection/mod.rs, so they'll conflict, and #4042 has no effect once #3948 lands. I'd close this one and focus on #3948. The only reason to keep it is as a one-line stopgap if #3948 is still far from merging. I haven't changed this branch.

Summary
  • Warming up the performance wizard...
  • Handling comment — Comment handling finished successfully

Learnings updated. See what CodSpeed remembers about this repository.

Was this response helpful? React with 👍 or 👎 to help us improve CodSpeedBot.

@codspeed
codspeed Bot requested a review from jesup October 6, 2026 08:27
@codspeed
codspeed Bot marked this pull request as ready for review October 6, 2026 08:27
@larseggert

Copy link
Copy Markdown
Collaborator

Redundant with #3948

@larseggert larseggert closed this Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants