Skip to content

libstd: Store capacity of std::vec::Vec on the heap? #67024

Closed
@michaelwoerister

Description

@michaelwoerister

This has probably been discussed before but in case it hasn't: It should be possible to store a vec's capacity as part of its heap allocation and thus shrink Vec from three to two words. It would make a difference for code that contains many empty Vecs and code that moves them around a lot. The downside is that the implementation is a bit more complicated and that the capacity can only be accessed after following a pointer. It might still be a worthwhile trade off.

cc @rust-lang/libs (and @nnethercote who likes this kind of thing :))

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-collectionsArea: `std::collections`C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions