Open
Description
The SerializedValues::with_capacity
constructor takes a capacity argument which is supposed to represent the expected total size of the serialized values, but currently we are passing the expected value count, which is guaranteed to be at least 4x too small as each value takes up at least 4 bytes in the serialized form (but usually more, 4 bytes is just for encoding size).
I think we should either:
- Get rid of
with_capacity
, or at least stop using it in the driver because the preallocated space will usually be orders of magnitude too small and it doesn't matter, - Add a method to
Value
interface which returns the expected serialized size, - Extend the
Value
interface so thatserialize
can write to other types thanVec<u8>
- this way we could implement aCountingWriter
which only counts bytes, then we could estimate the serialized size ofValue
by serializing theValue
usingCountingWriter
first, which should be a fast operation for most of the types.
If we decide to go with points 2/3, we could implement them together - the method mentioned in 2. would have a default implementation described in 3.