Repository navigation
Conversation
agnosticdev
approved these changes
Nov 26, 2026
`QUICStreamEcho_*` read at the QUIC stream with `readAndDrop()`, so nothing gated the allocations made by `NetworkConnection.receive(atLeast:atMost:)` as it runs `StreamEndpointFlowProtocol.read(minimumBytes:maximumBytes:in:)`. Changed: * Added the `EndpointFlowContentReceive_16KB` scenario to `QUICBenchmarks`. * Added `ContentReceiveHarness`, a `NoTransport` connection over `CustomLink` on a virtual clock that is handed bytes frame by frame. * Recorded the scenario's thresholds in each toolchain directory under `Thresholds/`. Result: * A 16 KB payload delivered as 12 frames of 1448 bytes is read with one `receive`; the measured window is that call and one turn of the scheduler. * The counts did not vary across five runs on one toolchain, so a change in the allocations of the read beyond the default allowances fails `thresholds check`. * The read allocates 25 times on macOS and 41 times on Linux. Every Linux window pays a fixed overhead of about 16 allocations, as `QUICIdle_10s` shows. * The `latest-beta` thresholds were recorded on macOS and the other directories from CI.
…tes:maximumBytes:)` The content form of `receive` built a fresh `[UInt8]` for every frame through `Deserializer.buffer(_:length:)`, appended it to `returnBuffer`, and let `returnBuffer` double with no reserve. For a 16 KB write at MTU 1500 this made 16 allocations on the reading side: 12 per-frame arrays plus 4 growths of `returnBuffer`. Changed: * Reserved `returnBuffer` once from `FrameArray.unclaimedLength` before reading. * Appended each frame's bytes straight from `Frame.bytes` instead of through a per-frame array. * Returned `nil` for an empty `FrameArray` up front; a frame with no bytes still yields an empty array. * Added `SwiftNetworkEndpointFlowContentReadTests` covering frames of different sizes, a `maximumBytes` smaller than the data, and an empty write. * Lowered the `EndpointFlowContentReceive_16KB` thresholds in each toolchain directory under `Thresholds/`. Result: * The read allocates one exactly sized array per call, in place of 16 for 12 frames; `EndpointFlowContentReceive_16KB` goes from 25 to 10 `mallocCountTotal` and from 24 to 9 `objectAllocCount` on macOS, and from 41 to 26 and from 40 to 25 on Linux. * `thresholds check` fails if the read goes back to a per-frame array. * The returned bytes, their order, and the finalizing of every frame are unchanged. * The new tests pin that behavior; they do not measure allocations.
rnro
force-pushed
the
content-read-reserve
branch
from
November 27, 2026 17:25
57eb92e to
a5c1cea
Compare
rnro
marked this pull request as ready for review
November 27, 2026 17:39
tfpauly
reviewed
Dec 1, 2026
| let sixteenKilobytePayload = [UInt8](repeating: 0xCD, count: 16 * 1024) | ||
|
|
||
| /// The payload of a TCP segment on a 1500 byte MTU with the timestamp option. | ||
| let tcpSegmentSize = 1448 |
Collaborator
There was a problem hiding this comment.
Why is the TCP segment size relevant in a QUIC benchmark?
| } else { | ||
| returnBuffer?.append(contentsOf: buffer) | ||
| if let bytes = frame.bytes { | ||
| bytes.withUnsafeBytes { returnBuffer.append(contentsOf: $0) } |
Collaborator
There was a problem hiding this comment.
One reason to use the read.buffer in the previous version was to avoid the unsafe here. Can we still do that?
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.
The content form of
receivebuilt a fresh[UInt8]for every frame throughDeserializer.buffer(_:length:), appended it toreturnBuffer, and letreturnBufferdouble with no reserve. For >Changed:
returnBufferonce fromFrameArray.unclaimedLengthbefore reading.Frame.bytesinstead of through a per-frame array.nilfor an emptyFrameArrayup front; a frame with no bytes still yields an empty array.SwiftNetworkEndpointFlowContentReadTestscovering frames of different sizes, amaximumBytessmaller than the data, and an empty write.EndpointFlowContentReceive_16KBthresholds in each toolchain directory underThresholds/.Result:
EndpointFlowContentReceive_16KBgoes from 25 to 10mallocCountTotaland from 24 to 9objectAllocCount.thresholds checkfails if the read goes back to a per-frame array.