Skip to content

Use growth factor 1.5x for read_buffer #502

@vsoulgard

Description

@vsoulgard

Change the buffer growth strategy in read_buffer::grow_to_fit() from allocating exactly required_size to allocate std::max(required_size, buffer_.size() * 1.5) or required_size * 1.5, because:

  1. This could reduce amount of reallocations (imagine situation where reallocation happens just for few bytes).
  2. This could reduce heap fragmentation in case we use std::max(required_size, buffer_.size() * 1.5), because we amortize future reallocations to match growth factor of 1.5.

But memory usage will be higher. In the worst case, the buffer capacity may grow to 1.5× the maximum message size, but that also mean we can avoid memmoves for such big messages if we use approach mentioned in #501

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions