Skip to content

Eliminate RTCP allocations - #403

Merged
kcaffrey merged 1 commit into
pion:mainfrom
kcaffrey:rtcp-allocs
Oct 2, 2026
Merged

kcaffrey merged 1 commit into
pion:mainfrom
kcaffrey:rtcp-allocs

Conversation

@kcaffrey

@kcaffrey kcaffrey commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Previously, receiving an RTCP packet would allocate in order to unmarshal and remarshal the packet and collect the destination SSRCs. The unmarshal and remarshal was needed to properly handle compound packets (see #359), and was performed even for non-compound packets.

This change uses the new API provided by pion/rtcp#223 to both split compound packets and collect destination SSRCs without allocations (by reusing slices, which is safe as decrypt is only called from a single goroutine).

There is a small intentional behavior change regarding invalid packets: previously these were skipped due to failures in either Unmarshal or Marshal, but now they are forwarded to the receiver so long as the compound framing is valid. This is consistent with RFC 3550 and RFC 5506 (see pion/rtcp#223 for more information on this).

A new test pins round-trip allocations to zero for RTCP, matching the existing test for RTP. This test also uncovered an allocation for GCM due to the AAD byte array escaping when sliced and passed as a parameter to another function, which is also fixed in this PR.

NOTE: Authentication-only GCM still allocates, but is left as-is as it isn't intended for production use anyway.

Previously, receiving an RTCP packet would allocate in order to
unmarshal and remarshal the packet and collect the destination SSRCs.
The unmarshal and remarshal was needed to properly handle compound
packets (see pion#359), and was performed even for non-compound
packets.

This change uses the new API provided by pion/rtcp#223 to both split
compound packets and collect destination SSRCs without allocations (by
reusing slices, which is safe as decrypt is only called from a single
goroutine).

There is a small intentional behavior change regarding invalid packets:
previously these were skipped due to failures in either Unmarshal or
Marshal, but now they are forwarded to the receiver so long as the
compound framing is valid. This is consistent with RFC 3550 and RFC
5506 (see pion/rtcp#223 for more information on this).

A new test pins round-trip allocations to zero for RTCP, matching the
existing test for RTP. This test also uncovered an allocation for GCM
due to the AAD byte array escaping when sliced and passed as a parameter
to another function, which is also fixed in this PR.

NOTE: Authentication-only GCM still allocates, but is left as-is as it
isn't intended for production use anyway.
@codecov

codecov Bot commented Oct 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.94%. Comparing base (d6f2397) to head (535e6ea).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #403      +/-   ##
==========================================
+ Coverage   90.90%   90.94%   +0.03%     
==========================================
  Files          20       20              
  Lines        1485     1491       +6     
==========================================
+ Hits         1350     1356       +6     
  Misses        135      135              
Flag Coverage Δ
go 90.94% <100.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@JoTurk JoTurk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

looks good

@JoTurk

JoTurk commented Oct 2, 2026

Copy link
Copy Markdown
Member

@kcaffrey thank you for all the optimizations <3

@kcaffrey
kcaffrey merged commit 508d3e9 into pion:main Oct 2, 2026
18 checks passed
@kcaffrey
kcaffrey deleted the rtcp-allocs branch October 2, 2026 00:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants