Eliminate RTCP allocations - #403
Merged
Merged
Conversation
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 Report✅ All modified and coverable lines are covered by tests. 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
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:
|
Member
|
@kcaffrey thank you for all the optimizations <3 |
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.
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.