Hi Cherry,
Any chance to revive the CLs in time to get them into 1.21? I've rebased them on top of a recent master, and things seem to work fine.
I went ahead and ran the encoding/binary benchmarks:
https://gist.github.com/lmb/4477812588a5ac23e0b58f5f780b383d Benchmarks that repeatedly call Write benefit from this change since the data argument doesn't escape anymore. This makes function which use a "temporary" struct to marshal into a wire format a bit cheaper. Not sure if I explained it properly, something like this:
func(w io.Writer, a ExportedType) error {
tmp := wireFormat{a.Foo, a.Bar}
return binary.Write(w, bo, tmp)
}
That still leaves the cost of the temporary buffer allocated by Write (which is much higher than the escaping interface), but with non-escaping reflect in place I want to experiment with an AppendByteOrder version of Write. Then we might be able to do zero-allocation binary marshaling while still using reflection behind the scenes.
Lorenz