Skip to content

Reuse the sent packet deque across sendFrames calls - #58

Open
glbrntt wants to merge 1 commit into
apple:mainfrom
glbrntt:reuse-packet-deque
Open

Reuse the sent packet deque across sendFrames calls#58
glbrntt wants to merge 1 commit into
apple:mainfrom
glbrntt:reuse-packet-deque

Conversation

@glbrntt

@glbrntt glbrntt commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Motivation:

Both sendFrames() overloads create a new deque of SentPacketRecord on every call, only to hand its contents to recovery and throw the storage away.

Modifications:

  • Store a deque on the QUICConnection and reuse it.
  • Take 'sentPackets' inout rather than consuming in Recovery.recordSentPackets. It already drained the storage in place so now the connection can reuse the empty deque.

Result:

  • Fewer allocations

@glbrntt

glbrntt commented Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

When running some http/3 benchmarks (100k requests, each a 1k download with 100 concurrent streams on one connection) this saves 100k allocs (only ~2% or so), but reduces total bytes allocated by ~15%.

Motivation:

Both sendFrames() overloads create a new deque of SentPacketRecord
on every call, only to hand its contents to recovery and
throw the storage away.

Modifications:

- Store a deque on the QUICConnection and reuse it.
- Take 'sentPackets' inout rather than consuming in
  Recovery.recordSentPackets. It already drained the storage in place so
  now the connection can reuse the empty deque.

Result:

- Fewer allocations
@glbrntt
glbrntt force-pushed the reuse-packet-deque branch from 1ca3472 to 32fe031 Compare July 28, 2026 14:22
// 'sentPackets' is held onto for the lifetime of the connection. If a send burst grows it
// beyond a certain limit then drop the capacity. This avoids bursty traffic bloating memory
// indefinitely.
if self.sentPackets.capacity > 512 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a setting in Preferences.swift

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