Skip to content

Fix uses of SerializedValues::with_capacity in the driver code #385

Open
@piodul

Description

@piodul

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:

  1. 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,
  2. Add a method to Value interface which returns the expected serialized size,
  3. Extend the Value interface so that serialize can write to other types than Vec<u8> - this way we could implement a CountingWriter which only counts bytes, then we could estimate the serialized size of Value by serializing the Value using CountingWriter 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    API-breakingThis might introduce incompatible API changesperformanceImproves performance of existing features

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions