bytebufferpool icon indicating copy to clipboard operation
bytebufferpool copied to clipboard

Go runtime adoption

Open jadbox opened this issue 9 years ago • 2 comments

I was thinking- couldn't Go perform pooling for byte arrays natively and implicitly? Thought I'd bring it up here if this sounds like a logical optimization the runtime could perform.

jadbox avatar Jul 10 '16 16:07 jadbox

It's very difficult to implement byte buffer pooling that satisfies all the needs. butebufferpool isn't a silver bullet yet.

It performs better than a dumb sync.Pool when working with variously-sized byte buffers when a small fraction of such buffers has much higher size comparing to the rest (this helps real-world apps based on fasthttp and quicktemplate).

But it still may waste a lot of memory in the case of buffers with wide-range equally distributed sizes. It is advisable to create a separate pool per each use in this case - see Pool docs for details.

valyala avatar Jul 12 '16 06:07 valyala

@valyala i have the exact situation from your comment, any chance that you can show me some example how to get it done?

jjhesk avatar Feb 23 '19 06:02 jjhesk