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

bytes: optimize Buffer.WriteByte #17857

Closed
dsnet opened this issue Nov 8, 2016 · 4 comments
Closed

bytes: optimize Buffer.WriteByte #17857

dsnet opened this issue Nov 8, 2016 · 4 comments

Comments

@dsnet
Copy link
Member

dsnet commented Nov 8, 2016

According to a profiling data from a large number of servers at Google, bytes.Buffer.WriteByte is within the top 100 functions by CPU time. Each call to WriteByte requires another method call to grow(1). We should optimize this by doing a special check if we can simply grow the capacity by 1 before calling that method.

@dsnet dsnet added this to the Go1.9 milestone Nov 8, 2016
@dsnet
Copy link
Member Author

dsnet commented Nov 8, 2016

Same quick-path optimization can be applied to the following methods:

  • Write
  • WriteString
  • WriteRune

These all also appear within the top 500 functions by CPU time.

@gopherbot
Copy link

CL https://golang.org/cl/32921 mentions this issue.

@gopherbot
Copy link

CL https://golang.org/cl/32922 mentions this issue.

@dsnet dsnet self-assigned this Dec 9, 2016
@gopherbot
Copy link

CL https://golang.org/cl/42813 mentions this issue.

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

No branches or pull requests

2 participants