Open yuanchao0310 opened 2 years ago
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)
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
@pionbot @Sean-Der someone can help review?
No need to alloc empty slice if CSRC=0 Extensions always reset to zero length when unmarshal
Description
Reference issue