Skip to content

Improve performance by pre-allocating vectors #5877

@abhijat

Description

@abhijat

In some cases we create vectors for response eg OpResult<StringVec> dfly::OpInter(const dfly::Transaction* t, dfly::EngineShard* es, bool remove_first) and push elements into it iterating over a set.

These vectors can end up being multiple 100s of MiB in size (250MiB vectors have been observed).

This ends up in a lot of reallocations over time as the vector grows and potentially moves to new memory pages.

It can be more efficient (to be tested if it actually is) to first determine the result size, allocate vector with that capacity, and then add results to it, or even use a chunked vector similar to deque but with configurable chunk size, which chains together contiguous blocks of memory and allocates a new one when the existing one is full.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions