tendermint/go-amino

Remove the usage of "writers" for speedups

ValarDragon opened this issue · 1 comments

Basically due to our usage of "writers" in all of the encode functions, the buffer in all of these is forced to escape to the heap. (As it can't tell where the pointer to it ends, due to writer being an interface)

Run

go build -gcflags -m -o test.txt encoder.go amino.go codec.go reflect.go binary-encode.go binary-decode.go json-encode.go json-decode.go decoder.go

and enjoy the interesting knowledge from the escape analysis :D
one example:
./encoder.go:39:22: buf escapes to heap.

That's pretty cool! I didn't know you can do this so easily (escape analysis).

Even if we don't have any numbers on how beneficial it will be, it should be simple enough to change the encode function to be of the form:
EncodeT(thing T) []byte (instead currently EncodeT(w io.Writer, thing T) error)

Yet this change would be breaking. Hence, I think this should be a pre-launch priority.
Do you agree @jaekwon @ebuchman ?

Are the writers in amino used to directly write to a network connection? Is that important?
In this context: protobuf uses a Buffer instead of a writer to append to the same buffer (see 1).