bitsery icon indicating copy to clipboard operation
bitsery copied to clipboard

pass cursor and needed byte space to BufferAdapterTraits::increaseBufferSize

Open victorstewart opened this issue 3 years ago • 2 comments

two insights seen when resizing buffers...

  1. when inserting an object much larger than the current buffer size, the current implementation will loop many times until the buffer grows large enough, burning several unnecessary allocations and memcpy-s in the worst case. so inform the implementation how many bytes we need.

  2. when implementing an alloc + memcpy, since the buffer's length isn't updated until after the serialization, we're forced to copy the entire capacity. though this capacity is insufficient to accommodate the new addition, we still might be copying excess bytes. very mildly cleaner this way. wouldn't warrant a PR without 1) though.

victorstewart avatar Apr 10 '22 15:04 victorstewart

the 1st test failed because the couldn't pull a resource from the network, and the other 2 because the parameters are currently unused in the StdContainer implementation.

victorstewart avatar Apr 10 '22 15:04 victorstewart

Hello, Actually, this is very good idea, especially the part of enforcing at least bytes allocation. I want to play with this idea, as it might bring some performance improvements basically for free!

fraillt avatar Apr 16 '22 14:04 fraillt

This is implemented in v5.2.3.

fraillt avatar Dec 01 '22 12:12 fraillt