Skip to content

Conversation

yuanchao0310
Copy link
Contributor

No need to alloc empty slice if CSRC=0
Extensions always reset to zero length when unmarshal

Description

Reference issue

@yuanchao0310
Copy link
Contributor Author

yuanchao0310 commented Jun 9, 2022

don't make empty slice can reduce bench test time.

Test result
goos: darwin
goarch: amd64
pkg: github.com/pion/rtp/v2
cpu: Intel(R) Core(TM) i7-1068NG7 CPU @ 2.30GHz

name                                      old time/op    new time/op    delta
UnmarshalHeader/NewStructWithoutCSRC-8    52.8ns ± 1%    47.7ns ± 1%  -9.67%  (p=0.008 n=5+5)
UnmarshalHeader/NewStructWithCSRC-8       68.2ns ±13%    67.6ns ±14%    ~     (p=1.000 n=5+5)

name                                      old alloc/op   new alloc/op   delta
UnmarshalHeader/NewStructWithoutCSRC-8     32.0B ± 0%     32.0B ± 0%    ~     (all equal)
UnmarshalHeader/NewStructWithCSRC-8        40.0B ± 0%     40.0B ± 0%    ~     (all equal)

name                                       old allocs/op  new allocs/op  delta
UnmarshalHeader/NewStructWithoutCSRC-8      1.00 ± 0%      1.00 ± 0%    ~     (all equal)
UnmarshalHeader/NewStructWithCSRC-8         2.00 ± 0%      2.00 ± 0%    ~     (all equal)

@yuanchao0310
Copy link
Contributor Author

Issue #79 discuss: when CSRC empty, should we Unmarshal it as nil or []uint32{}, and choose to use []uint32{}.
but from test result, make empty slice still cost cpu time, maybe use nil is better

@yuanchao0310
Copy link
Contributor Author

@pionbot @Sean-Der someone can help review?

@Sean-Der Sean-Der force-pushed the unmarshal_perf branch 2 times, most recently from 0275cba to bf1bf5e Compare October 17, 2025 19:41
Copy link

codecov bot commented Oct 17, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.09%. Comparing base (0a6cec7) to head (a6628ed).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #188      +/-   ##
==========================================
- Coverage   91.22%   91.09%   -0.14%     
==========================================
  Files          26       26              
  Lines        3191     3188       -3     
==========================================
- Hits         2911     2904       -7     
- Misses        218      221       +3     
- Partials       62       63       +1     
Flag Coverage Δ
go 91.09% <100.00%> (-0.14%) ⬇️
wasm 90.55% <100.00%> (-0.14%) ⬇️

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.

No need to alloc empty slice if CSRC=0
@Sean-Der
Copy link
Member

Thank you so much for this PR @yuanchao0310

I am so sorry it took so long to merge! Totally poor management on my end, this is a great improvement.

@Sean-Der Sean-Der merged commit f4f616d into pion:master Oct 17, 2025
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants