sysenc: dealing with []struct{ ... }
forces allocations
#1255
Labels
help wanted
Extra attention is needed
[]struct{ ... }
forces allocations
#1255
We currently inherit an allocation problem from
encoding/binary
:binary.Size
doesn't cache it's result for slices of structs. This means that our zero-alloc code path viasysenc
isn't zero-alloc, since we end up hitting an allocation in reflect.A benchmark to illustrate:
Going from a single
explicitPad
to a slice of them causes an allocation. The allocation happens inbinary.dataSize
:In the past I've fixed the same problem for plain structs using a cache: golang/go@c9d89f6 I didn't take slices of structs into account since they are kind of esoteric. Turns out we now need to encode those when doing zero-alloc batch lookups, see #1254
One option is to fix this upstream, but it'll take a long time for this to reach us. I think we should fix upstream and in addition copy the implementation of binary.Size and fix the problem in our copy.
The text was updated successfully, but these errors were encountered: