Reduce TWCC sender allocations#426
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #426 +/- ##
==========================================
- Coverage 80.13% 80.09% -0.04%
==========================================
Files 88 88
Lines 4617 4623 +6
==========================================
+ Hits 3700 3703 +3
- Misses 735 736 +1
- Partials 182 184 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Record stored the unwrapped sequence number by taking its address, which heap-allocates the local on every call, whether or not the branch is taken. Updates now go through a setter that writes into a single reused allocation. addReceived allocated one rtcp.RecvDelta per received packet. Store values and build the pointer slice once per feedback in getRTCP. BenchmarkRecord: 21.1ns/op 1 alloc -> 6.9ns/op 0 allocs. BenchmarkRecordAndBuildFeedbackPacket (100 packets per feedback): 4546ns/op 322 allocs -> 2270ns/op 21 allocs.
kcaffrey
force-pushed
the
reduce-allocations
branch
from
July 21, 2026 00:06
d6f41c2 to
34e99f0
Compare
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.
Recorder.Recordheap-allocates on every call: it stores the unwrapped sequence number intostartSequenceNumberby taking the address of a local, which moves the local to the heap whether or not the branch is taken. SinceRecordruns once per received RTP packet, this costs one allocation per packet. Updates now go through a setter that writes into a single reused allocation.feedback.addReceivedalso allocated one*rtcp.RecvDeltaper received packet. Deltas are now accumulated by value, and the[]*rtcp.RecvDeltathat the rtcp API requires is materialized once per feedback packet ingetRTCP, which hands ownership of the backing array to the packet.No exported API or behavior changes.
Benchmarks (added in this PR, run on main vs this branch on a M2 MacBook Air; the second records 100 packets per feedback):
BenchmarkRecordBenchmarkRecordAndBuildFeedbackPacketTestRecordDoesNotAllocateInSteadyStatepins the steady-stateRecordpath at zero allocations.