Why lib.Buffer and not bytes.Buffer? #55
Replies: 4 comments 4 replies
-
Thanks for the great question. Yeah, they look very similar, and I really don't remember the reason why I choose to write my own. There might have been some limitations. I will take a look at this code a bit later. Thanks for the good pointing. |
Beta Was this translation helpful? Give feedback.
-
The reason for making lib.Buffer was the need to access the undelaying slice without making a call Bytes which is getting expensive for the highload parts of the code. As an example https://github.com/halturin/ergo/blob/master/dist/dist.go#L950 |
Beta Was this translation helpful? Give feedback.
-
bytes.Buffer.Bytes performs no allocations. |
Beta Was this translation helpful? Give feedback.
-
I finally tried to use bytes.Buffer (branch bytesBuffer) now I can prove it's more than 3 times slower than my lib.Buffer. Here is the bench results with bytes.Buffer so, its not bad sometimes to make custom solutions :) |
Beta Was this translation helpful? Give feedback.
-
Your lib.Buffer type is very interesting! It has many peculiar capabilities and constraints. What advantages does it have over a pooled bytes.Buffer? e.g.
Beta Was this translation helpful? Give feedback.
All reactions