rtp icon indicating copy to clipboard operation
rtp copied to clipboard

Improve unmarshal header

Open yuanchao0310 opened this issue 3 years ago • 3 comments

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

Description

Reference issue

yuanchao0310 avatar Jun 09 '22 14:06 yuanchao0310

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 avatar Jun 09 '22 15:06 yuanchao0310

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 avatar Jun 09 '22 15:06 yuanchao0310

@pionbot @Sean-Der someone can help review?

yuanchao0310 avatar Jun 13 '22 02:06 yuanchao0310