-
Notifications
You must be signed in to change notification settings - Fork 274
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
benchmarks: expensive/inefficient use of bytes.Buffer and .Reset() in benchmarking #451
Comments
So I see the purpose here is to pass in 2 different styles of *bytes.Buffer, one freshly allocated then the other with .Grow invoked, however, the use of buf.Reset() is unnecessary as the buffer is already fresh. |
The benchmarks are probably to serve as a reminder to the authors, but I don't think the Node_WriteBytes/*Allocate distinctions are necessary given that they measure use of *bytes.Buffer, but whatever. Just the buf.Reset() needs to be removed. |
…ffer After a bytes.Buffer has been freshly created, there is no need to invoke .Reset. Fixes cosmos#451
thanks! |
If we examine say node_test.go we can see this code
iavl/node_test.go
Lines 164 to 168 in ed98044
iavl/node_test.go
Lines 172 to 176 in ed98044
but notice in there, we unfortunately do the following
where after creating a new bytes.Buffer, we invoke buf.Reset() -- this is firstly unnecessary, but even more, this pollutes the benchmark with the allocation to a bytes.Buffer yet we are supposed to be focusing on benchmarking node.writeBytes. With the use of buf.Reset() it seems like the callers wanted to reuse the bytes.Buffer. The correct usage is the following
The results are stark when fixed
The text was updated successfully, but these errors were encountered: