-
Notifications
You must be signed in to change notification settings - Fork 117
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
decoders: replace binary.Read with a version without reflection and allocations #141
Conversation
7e5362b
to
e65432c
Compare
By using the |
I may have introduced a regression, let me investigate! |
e65432c
to
c797534
Compare
OK for now. I have fixed the bug. Previously, when we provide |
``` benchmark old ns/op new ns/op delta BenchmarkDecodeEncodeNetflow/with_encoding-12 7664 7548 -1.51% BenchmarkDecodeEncodeNetflow/without_encoding-12 7273 6872 -5.51% BenchmarkDecodeEncodeSflow/with_encoding-12 14029 9905 -29.40% BenchmarkDecodeEncodeSflow/without_encoding-12 13784 9245 -32.93% benchmark old allocs new allocs delta BenchmarkDecodeEncodeNetflow/with_encoding-12 143 134 -6.29% BenchmarkDecodeEncodeNetflow/without_encoding-12 143 134 -6.29% BenchmarkDecodeEncodeSflow/with_encoding-12 295 137 -53.56% BenchmarkDecodeEncodeSflow/without_encoding-12 295 137 -53.56% benchmark old bytes new bytes delta BenchmarkDecodeEncodeNetflow/with_encoding-12 8272 8160 -1.35% BenchmarkDecodeEncodeNetflow/without_encoding-12 8272 8160 -1.35% BenchmarkDecodeEncodeSflow/with_encoding-12 9816 8216 -16.30% BenchmarkDecodeEncodeSflow/without_encoding-12 9816 8216 -16.30% ``` "old" is still before using the fork. See netsampler/goflow2#141 for details of the fix.
c797534
to
34e153f
Compare
Instead of allocating small slices, we rely on the fact that most call sites are providing a `bytes.Buffer` and use the `Next()` method. For sFlow decoding, in my case, we get a 33% speedup. A `bytes.Reader` would even be more efficient, but unfortunately, they don't have a `Next()` method. While Go should be smart enough to make the allocation of `bs` on the stack, it does not, even when `io.ReadFull()` is inlines. ``` decoders/utils/utils.go:23:13: make([]byte, n) escapes to heap ```
34e153f
to
7562215
Compare
Added benchmark:
|
Will integrate it with v2 as well. |
See #140. Not really tested. Still need to get rid of
bytes.Buffer
.