bytebufferpool icon indicating copy to clipboard operation
bytebufferpool copied to clipboard

[Question] append vs. bytes.Buffer-like "manual cap/len check and copy"

Open metaleap opened this issue 7 years ago • 0 comments

I noticed your ByteBuffer grows via append, whereas we know the bytes.Buffer grows by hand-coded comparison of cap/len and enlarging/copying when needed.

For this very small specific sub-aspect of your overall buffer-pool project, did you bench both approaches? Did you:

  • verify append to be visibly, noticably, consistently "faster"/more-performant (perhaps because it compiles to better asm..) than a hand-rolled grow logic?
  • or did you just go for append for the simplicity? :smirk:

I'm curious in this mainly because I too keep around a lean tiny private alternative to bytes.Buffer (without your pooling aspects — not needed so far) and I was wondering if append might not be "intrinsically preferable", after all this growth logic is exactly its purpose. :grin: but then it makes me wonder why bytes.Buffer went for hand-rolled growth and avoiding append.

Since you have seen more heavy loads in your real-world projects so far than I did in my still-toy-stage usage so far, I figured you're the guy whose opinion to ask! =)

metaleap avatar Mar 14 '18 21:03 metaleap