1
0
mirror of https://github.com/netsampler/goflow2.git synced 2024-05-06 15:54:52 +00:00
Vincent Bernat 66b47ee328 decoders: replace binary.Read with a version without reflection and allocations (#141)
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
```
2023-08-18 19:38:00 -07:00
..
2023-08-09 19:49:00 -07:00
2023-03-28 22:05:47 -07:00