-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Use mc.buf as scratchpad for intarpolation #318
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
Use mc.buf as scratchpad for intarpolation #318
Conversation
methane
commented
Feb 18, 2015
I can remove last one allocation: Stop using |
9b7ffba
to
545d7e7
Compare
I'm opposed to it, I like having the packet building in one place. |
return "", driver.ErrSkip | ||
} | ||
estimated += len(query) | ||
buffSize := max |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bufSize
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
What allocation exactly are you trying to eliminate? |
|
||
buf := make([]byte, 0, estimated) | ||
buf := mc.buf.takeBuffer(buffSize)[:0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This allocation is removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean by stop using mc.exec()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think he means the conversion of the query from []byte to string to []byte
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I mean it.
Future Go may be able to optimize it, but I think Go 1.5 will not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Draft it. If it doesn't get too dirty, I would be fine with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And if that is fine, it can be applied in other areas, too.
We could e.g. have a variable-cached version of a full COM_QUIT and COM_STMT_CLOSE packet. The former can be sent as is, the letter only has to have the sequence number changed...
But that scatters the network Write
calls to multiple places and makes maintaining the driver a little harder.
b6519ad
to
cc1ec6b
Compare
packet size is len(query) + 4. This size is used just after interpolate.
fixed. |
cc1ec6b
to
4ea43cb
Compare
benchmark old ns/op new ns/op delta BenchmarkInterpolation 1900 1363 -28.26% benchmark old allocs new allocs delta BenchmarkInterpolation 2 1 -50.00% benchmark old bytes new bytes delta BenchmarkInterpolation 448 160 -64.29%
4ea43cb
to
e3e2d32
Compare
Now |
LGTM! |
Use mc.buf as scratchpad for intarpolation