Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve unmarshal header #188

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

yuanchao0310
Copy link

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

Description

Reference issue

No need to alloc empty slice if CSRC=0
Extensions always reset to zero length when unmarshal
@yuanchao0310
Copy link
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
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
Author

@pionbot @Sean-Der someone can help review?

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.

1 participant