io: optimize WriteString with a pool of buffer #28311
Labels
NeedsDecision
Feedback is required from experts, contributors, and/or the community before a change can be made.
Performance
Milestone
The current implementation of
io.WriteString
allocates a[]byte
if the writer doesn't implementStringWriter
.I think we can avoid this memory allocation by using a pool of buffer.
I wrote a proof of concept:
A benchmark:
The benchmark result:
I know we can't import
bytes
inio
.A real implementation would require to copy a private implementation of
bytes.Buffer
toio
.The text was updated successfully, but these errors were encountered: