Repository navigation
Conversation
…space `Recovery.InnerState.reset` replaced both ACK bitstrings with new `AckBitstring()` values, allocating two 512 byte arrays and freeing the old ones on every reset. A connection resets a packet number space when it discards that space's keys during the handshake, and closing a connection resets every space. Changed: * Added `AckBitstring.reset()`, which zero-fills the existing words and returns to the initial word. * Used `AckBitstring.reset()` in `Recovery.InnerState.reset` instead of constructing new bitstrings. Result: * A `QUICHandshake` iteration, which runs a client and a server, makes 20 fewer allocations (1929 to 1909). * A `QUICConnectionSetup` iteration makes 18 fewer allocations (657 to 639). * The stream echo and stream churn benchmarks make the same number of allocations as before.
`QUICConnection.init` builds a placeholder `Recovery` that `setup` immediately replaces. Each `Recovery` allocated an `AckBitstring` of 64 words (512 bytes) and room for 10 outstanding packets for every packet number space, whether or not the space ever carried a packet. `Recovery.init` therefore runs twice per connection on each side, and together with the in-place reset it accounts for about 23 allocations of a handshake per side. Changed: * Started `AckBitstring` with no words; `nset` and `xor` grow it on demand. * Reserved the full capacity in `AckBitstring.resize(to:)` so growth is a single allocation. * Started `outstandingPackets` as an empty deque that `insertSentPacket` sizes for 10 entries on the first insert. * Updated `testBitstringGrowth` to expect an empty bitstring to hold no words. Result: * Constructing a `Recovery` allocates nothing. * A `QUICHandshake` iteration, which runs a client and a server, makes 26 fewer allocations (1909 to 1883). * A `QUICConnectionSetup` iteration makes 35 fewer allocations (639 to 604). * The stream echo and stream churn benchmarks make the same number of allocations as before.
rnro
marked this pull request as ready for review
November 26, 2026 16:27
rnro
requested review from
agnosticdev,
ekinnear,
kkuk24,
rpaulo and
tfpauly
as code owners
November 26, 2026 16:27
agnosticdev
reviewed
Nov 26, 2026
| if outstandingPackets.capacity == 0 { | ||
| // Geometric growth from an empty deque would reallocate several times before | ||
| // reaching a typical flight size; jump straight to it. | ||
| outstandingPackets.reserveCapacity(Self.initialOutstandingPacketsCapacity) |
Collaborator
There was a problem hiding this comment.
We could probably reserve the capacity of 5 for the initial and handshake and then do 10 for the application space.
| @@ -1,5 +1,5 @@ | |||
| { | |||
| "mallocCountTotal" : 80988, | |||
| "mallocCountTotal" : 80996, | |||
Collaborator
There was a problem hiding this comment.
Are these numbers just variable?
tfpauly
approved these changes
Dec 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Allocate
Recoverystorage lazily and clearAckBitstringstorage in placeQUICConnection.initbuilds a placeholderRecoverythatsetupimmediately replaces, and eachRecoveryallocated anAckBitstringof 64 words (512 bytes) and room for 10 outstanding packets for every packet number space, whether or not the space ever carried a packet.Recovery.InnerState.resetalso replaced both ACK bitstrings with new ones, allocating two 512 byte arrays and freeing the old ones on every reset.Recovery.initruns twice per connection on each side, and a connection resets a packet number space when it discards that space's keys during the handshake and again when it closes.This is two commits that can be reviewed separately.
Changed:
AckBitstring.reset(), which zero-fills the existing words, and used it inRecovery.InnerState.resetinstead of constructing new bitstrings.AckBitstringwith no words;nsetandxorgrow it on demand, andresize(to:)reserves the full capacity so growth is a single allocation.outstandingPacketsas an empty deque thatinsertSentPacketsizes for 10 entries on the first insert.testBitstringGrowthto expect an empty bitstring to hold no words.Result:
Recoveryallocates nothing.