Skip to content

RawVec growth strategy can be more efficient #111307

Closed as not planned
Closed as not planned
@handsomefox

Description

@handsomefox

Currently, the RawVec implementation tries to double its internal capacity every time it has to grow, as can be seen in:

let cap = cmp::max(self.cap * 2, required_cap);

But, according to Facebook's FBVector memory handling: it is suboptimal, as "it can be mathematically proven that a growth factor of 2 is rigorously the worst possible because it never allows the vector to reuse any of its previously-allocated memory" because "any new chunk requested will be larger than all previously used chunks combined, so the vector must crawl forward in memory; it can't move back to its deallocated chunks. But any number smaller than 2 guarantees that you'll at some point be able to reuse the previous chunks."

They use a growth factor of 1.5.

Maybe it is worth considering changing the growth factor for the standard library to a theoretically more optimal value.

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