srtp icon indicating copy to clipboard operation
srtp copied to clipboard

Reduce allocations in encrypt/decrypt RTP

Open thesyncim opened this issue 2 months ago • 3 comments

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 avatar Dec 19 '25 17:12 thesyncim

Beautiful, nice work @thesyncim :)

Sean-Der avatar Dec 19 '25 18:12 Sean-Der

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 82.65%. Comparing base (1156dbf) to head (7b0bd25).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #355      +/-   ##
==========================================
+ Coverage   82.64%   82.65%   +0.01%     
==========================================
  Files          19       19              
  Lines        1458     1459       +1     
==========================================
+ Hits         1205     1206       +1     
  Misses        140      140              
  Partials      113      113              
Flag Coverage Δ
go 82.65% <100.00%> (+0.01%) :arrow_up:

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

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

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

codecov[bot] avatar Dec 19 '25 18:12 codecov[bot]

cc @atoppi

thesyncim avatar Dec 19 '25 18:12 thesyncim