Skip to content

Conversation

@thesyncim
Copy link
Contributor

@thesyncim thesyncim commented Dec 19, 2025

goarch: arm64                                                                                                                                                                                                        
pkg: github.com/pion/srtp/v3                                                                                                                                                                                         
cpu: Apple M2 Pro                                                                                                                                                                                                    
                              │ bench_old.txt │            bench_new.txt            │                                                                                                                                
                              │    sec/op     │    sec/op     vs base               │                                                                                                                                
EncryptRTP/CTR-100-10            385.3n ±  8%   354.1n ±  6%   -8.11% (p=0.002 n=6)                                                                                                                                  
EncryptRTP/CTR-1000-10           1.574µ ±  4%   1.558µ ±  6%        ~ (p=0.366 n=6)                                                                                                                                  
EncryptRTP/GCM-100-10            247.7n ±  9%   211.2n ±  6%  -14.76% (p=0.002 n=6)                                                                                                                                  
EncryptRTP/GCM-1000-10           510.6n ±  7%   482.2n ± 15%        ~ (p=0.310 n=6)                                                                                                                                  
EncryptRTPInPlace/CTR-100-10     363.0n ± 22%   336.7n ±  1%   -7.23% (p=0.002 n=6)                                                                                                                                  
EncryptRTPInPlace/CTR-1000-10    1.378µ ±  8%   1.369µ ±  9%        ~ (p=0.589 n=6)                                                                                                                                  
EncryptRTPInPlace/GCM-100-10     199.0n ± 24%   183.3n ±  4%   -7.89% (p=0.002 n=6)                                                                                                                                  
EncryptRTPInPlace/GCM-1000-10    352.2n ± 11%   305.6n ±  8%  -13.23% (p=0.015 n=6)                                                                                                                                  
DecryptRTP/CTR-10                286.2n ±  5%   262.8n ±  3%   -8.19% (p=0.002 n=6)                                                                                                                                  
DecryptRTP/GCM-10                168.2n ± 44%   151.3n ±  4%  -10.05% (p=0.002 n=6)                                                                                                                                  
geomean                          408.5n         376.8n         -7.77%                                                                                                                                                
                                                                                                                                                                                                                     
                              │ bench_old.txt │             bench_new.txt             │                                                                                                                              
                              │      B/s      │      B/s        vs base               │                                                                                                                              
EncryptRTP/CTR-100-10           277.2Mi ±  7%    301.7Mi ±  6%   +8.80% (p=0.002 n=6)                                                                                                                                
EncryptRTP/CTR-1000-10          613.6Mi ±  4%    619.9Mi ±  6%        ~ (p=0.372 n=6)                                                                                                                                
EncryptRTP/GCM-100-10           431.3Mi ± 10%    505.8Mi ±  6%  +17.26% (p=0.002 n=6)                                                                                                                                
EncryptRTP/GCM-1000-10          1.846Gi ±  6%    1.955Gi ± 13%        ~ (p=0.310 n=6)                                                                                                                                
EncryptRTPInPlace/CTR-100-10    294.3Mi ± 18%    317.3Mi ±  1%   +7.81% (p=0.002 n=6)                                                                                                                                
EncryptRTPInPlace/CTR-1000-10   700.4Mi ±  7%    705.1Mi ±  9%        ~ (p=0.589 n=6)                                                                                                                                
EncryptRTPInPlace/GCM-100-10    537.0Mi ± 19%    582.7Mi ±  4%   +8.52% (p=0.002 n=6)                                                                                                                                
EncryptRTPInPlace/GCM-1000-10   2.676Gi ± 12%    3.084Gi ±  7%  +15.25% (p=0.015 n=6)                                                                                                                                
DecryptRTP/CTR-10               93.29Mi ±  5%   101.60Mi ±  3%   +8.91% (p=0.002 n=6)                                                                                                                                
DecryptRTP/GCM-10               192.9Mi ± 31%    214.3Mi ±  4%  +11.10% (p=0.002 n=6)                                                                                                                                
geomean                         487.4Mi          528.4Mi         +8.41%                                                                                                                                              
                                                                                                                                                                                                                     
                              │ bench_old.txt │            bench_new.txt            │                                                                                                                                
                              │     B/op      │     B/op      vs base               │                                                                                                                                
EncryptRTP/CTR-100-10              252.0 ± 0%     224.0 ± 0%  -11.11% (p=0.002 n=6)                                                                                                                                  
EncryptRTP/CTR-1000-10           1.121Ki ± 0%   1.094Ki ± 0%   -2.44% (p=0.002 n=6)                                                                                                                                  
EncryptRTP/GCM-100-10              240.0 ± 0%     224.0 ± 0%   -6.67% (p=0.002 n=6)                                                                                                                                  
EncryptRTP/GCM-1000-10           1.234Ki ± 0%   1.219Ki ± 0%   -1.27% (p=0.002 n=6)                                                                                                                                  
EncryptRTPInPlace/CTR-100-10      124.00 ± 0%     96.00 ± 0%  -22.58% (p=0.002 n=6)                                                                                                                                  
EncryptRTPInPlace/CTR-1000-10     124.00 ± 0%     96.00 ± 0%  -22.58% (p=0.002 n=6)                                                                                                                                  
EncryptRTPInPlace/GCM-100-10      112.00 ± 0%     96.00 ± 0%  -14.29% (p=0.002 n=6)                                                                                                                                  
EncryptRTPInPlace/GCM-1000-10     112.00 ± 0%     96.00 ± 0%  -14.29% (p=0.002 n=6)                                                                                                                                  
DecryptRTP/CTR-10                  148.0 ± 0%     120.0 ± 0%  -18.92% (p=0.002 n=6)                                                                                                                                  
DecryptRTP/GCM-10                  160.0 ± 0%     144.0 ± 0%  -10.00% (p=0.002 n=6)                                                                                                                                  
geomean                            229.2          200.1       -12.71%                                                                                                                                                
                                                                                                                                                                                                                     
                              │ bench_old.txt │           bench_new.txt           │                                                                                                                                  
                              │   allocs/op   │ allocs/op   vs base               │                                                                                                                                  
EncryptRTP/CTR-100-10              4.000 ± 0%   2.000 ± 0%  -50.00% (p=0.002 n=6)                                                                                                                                    
EncryptRTP/CTR-1000-10             4.000 ± 0%   2.000 ± 0%  -50.00% (p=0.002 n=6)                                                                                                                                    
EncryptRTP/GCM-100-10              3.000 ± 0%   2.000 ± 0%  -33.33% (p=0.002 n=6)                                                                                                                                    
EncryptRTP/GCM-1000-10             3.000 ± 0%   2.000 ± 0%  -33.33% (p=0.002 n=6)                                                                                                                                    
EncryptRTPInPlace/CTR-100-10       3.000 ± 0%   1.000 ± 0%  -66.67% (p=0.002 n=6)                                                                                                                                    
EncryptRTPInPlace/CTR-1000-10      3.000 ± 0%   1.000 ± 0%  -66.67% (p=0.002 n=6)                                                                                                                                    
EncryptRTPInPlace/GCM-100-10       2.000 ± 0%   1.000 ± 0%  -50.00% (p=0.002 n=6)                                                                                                                                    
EncryptRTPInPlace/GCM-1000-10      2.000 ± 0%   1.000 ± 0%  -50.00% (p=0.002 n=6)                                                                                                                                    
DecryptRTP/CTR-10                  4.000 ± 0%   2.000 ± 0%  -50.00% (p=0.002 n=6)                                                                                                                                    
DecryptRTP/GCM-10                  3.000 ± 0%   2.000 ± 0%  -33.33% (p=0.002 n=6)                                                                                                                                    
geomean                            3.016        1.516       -49.74%

@thesyncim thesyncim force-pushed the encrypt-decrypt-allocs branch from d611908 to b22aa75 Compare December 19, 2025 17:58
@Sean-Der
Copy link
Member

Beautiful, nice work @thesyncim :)

@codecov
Copy link

codecov bot commented Dec 19, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.63%. Comparing base (3ad2ef9) to head (a13e65a).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #355      +/-   ##
==========================================
- Coverage   82.64%   82.63%   -0.02%     
==========================================
  Files          19       19              
  Lines        1458     1457       -1     
==========================================
- Hits         1205     1204       -1     
  Misses        140      140              
  Partials      113      113              
Flag Coverage Δ
go 82.63% <100.00%> (-0.02%) ⬇️

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

☔ View full report in Codecov by Sentry.
📢 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.

@thesyncim thesyncim force-pushed the encrypt-decrypt-allocs branch from b22aa75 to 8f658b6 Compare December 19, 2025 18:07
@thesyncim
Copy link
Contributor Author

cc @atoppi

Copy link
Member

@JoTurk JoTurk left a comment

Choose a reason for hiding this comment

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

Change is amazing thank you.

@thesyncim thesyncim force-pushed the encrypt-decrypt-allocs branch from fb02431 to ae33de0 Compare December 19, 2025 21:20
@thesyncim thesyncim force-pushed the encrypt-decrypt-allocs branch from ae33de0 to 57d6a38 Compare December 19, 2025 21:29
@thesyncim thesyncim requested a review from JoTurk December 20, 2025 22:25
useCryptex bool

// Pre-allocated buffer for IV to avoid heap allocation in hot path
rtpIV [12]byte
Copy link

@asayyah asayyah Jan 2, 2026

Choose a reason for hiding this comment

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

assuming this is safe, wouldn't it better to just change rtpInitializationVector and rtpInitializationVector to directly use this buffer instead of allocating their own?

BTW I'm not familiar with this code base, so totally ignore me if it doesn't make sense.

Copy link
Member

Choose a reason for hiding this comment

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

@thesyncim Sorry i missed track of this PR.
what do you think about this refactor?

Copy link
Member

Choose a reason for hiding this comment

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

Oh that's a great idea @asayyah!

It's a super simple change @thesyncim I think will make the code easier to follow. Change that function to generateRTPInitializationVector and then we can merge.

Sorry I haven't been quicker on this :( it's a great change to get rid of these allocations.

Copy link
Member

Choose a reason for hiding this comment

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

If you don't have the time I can do it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can pick this up later today

Copy link
Contributor

Choose a reason for hiding this comment

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

I did that. Could you check if everything looks good?

@atoppi
Copy link
Contributor

atoppi commented Jan 9, 2026

I also did the same optimization for the RTCP path.

@atoppi atoppi force-pushed the encrypt-decrypt-allocs branch from aa390fb to 66f2a85 Compare January 9, 2026 12:11
Copy link
Member

@JoTurk JoTurk left a comment

Choose a reason for hiding this comment

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

looks good to me, thank you and sorry again that we lost track of this.

@JoTurk
Copy link
Member

JoTurk commented Jan 9, 2026

@atoppi Do you mind if you update this branch, a rebase or a merge commit will do it. I don't want to push to your branch in case you have local changes.

@atoppi
Copy link
Contributor

atoppi commented Jan 9, 2026

@atoppi Do you mind if you update this branch, a rebase or a merge commit will do it. I don't want to push to your branch in case you have local changes.

Done

@JoTurk JoTurk merged commit 030374f into pion:master Jan 9, 2026
18 checks passed
@JoTurk
Copy link
Member

JoTurk commented Jan 9, 2026

@thesyncim @atoppi thank you so much for this.

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.

5 participants