Skip to content

wire: add a function to trunctate an ACK frame#5476

Merged
marten-seemann merged 1 commit intomasterfrom
ack-frame-truncate
Dec 5, 2025
Merged

wire: add a function to trunctate an ACK frame#5476
marten-seemann merged 1 commit intomasterfrom
ack-frame-truncate

Conversation

@marten-seemann
Copy link
Copy Markdown
Member

It is expected that when packing an ACK frame, the packer calls Truncate to make sure that the ACK fits into the packet. This is faster, since we can skip the length calculation for small ACKs / large packet sizes.

name                                 old time/op    new time/op    delta
ACKSerialization/single_range-16       13.7ns ± 7%    13.4ns ± 3%   -2.30%  (p=0.013 n=18+19)
ACKSerialization/multiple_ranges-16    31.8ns ± 4%    26.0ns ± 5%  -18.06%  (p=0.000 n=19+20)

@marten-seemann marten-seemann changed the title wire: add a function to trunctate an ACK frame to a given size wire: add a function to trunctate an ACK frame Dec 5, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a Truncate method for ACK frames to optimize packet packing by allowing explicit size-based truncation before serialization, rather than computing size on every append. The change increases MaxNumAckRanges from 32 to 64 (still fitting in a single-byte varint) and removes the MaxAckFrameSize constant, shifting responsibility for size limits to the caller via the new Truncate method.

Key changes:

  • Adds AckFrame.Truncate() method with fast-path optimization for small frames
  • Updates MaxNumAckRanges from 32 to 64 to enable single-byte varint encoding
  • Simplifies loop constructs and optimizes Length() calculation

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
internal/protocol/params.go Removes MaxAckFrameSize constant and increases MaxNumAckRanges to 64 with updated documentation explaining single-byte varint constraint
internal/wire/ack_frame.go Adds Truncate() method, refactors numEncodableAckRanges() to accept size parameter, optimizes Length() calculation, simplifies loops, and fixes comment typo (NACK→ACK)
internal/wire/ack_frame_test.go Replaces size limit test with comprehensive truncation tests covering single/multiple ranges with/without ECN, adds truncation to benchmarks

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/wire/ack_frame.go Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/wire/ack_frame.go Outdated
@marten-seemann marten-seemann merged commit 6bf4231 into master Dec 5, 2025
37 checks passed
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