Skip to content
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

Remove the usage of "writers" for speedups #226

Open
ValarDragon opened this issue Sep 12, 2018 · 1 comment
Open

Remove the usage of "writers" for speedups #226

ValarDragon opened this issue Sep 12, 2018 · 1 comment

Comments

@ValarDragon
Copy link
Contributor

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.

@liamsi
Copy link
Contributor

liamsi commented Sep 12, 2018

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants