Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tiny Vecs are dumb. #72227

Merged
merged 1 commit into from
May 19, 2020
Merged

Tiny Vecs are dumb. #72227

merged 1 commit into from
May 19, 2020

Commits on May 18, 2020

  1. Tiny Vecs are dumb.

    Currently, if you repeatedly push to an empty vector, the capacity
    growth sequence is 0, 1, 2, 4, 8, 16, etc. This commit changes the
    relevant code (the "amortized" growth strategy) to skip 1 and 2 in most
    cases, instead using 0, 4, 8, 16, etc. (You can still get a capacity of
    1 or 2 using the "exact" growth strategy, e.g. via `reserve_exact()`.)
    
    This idea (along with the phrase "tiny Vecs are dumb") comes from the
    "doubling" growth strategy that was removed from `RawVec` in rust-lang#72013.
    That strategy was barely ever used -- only when a `VecDeque` was grown,
    oddly enough -- which is why it was removed in rust-lang#72013.
    
    (Fun fact: until just a few days ago, I thought the "doubling" strategy
    was used for repeated push case. In other words, this commit makes
    `Vec`s behave the way I always thought they behaved.)
    
    This change reduces the number of allocations done by rustc itself by
    10% or more. It speeds up rustc, and will also speed up any other Rust
    program that uses `Vec`s a lot.
    nnethercote committed May 18, 2020
    Configuration menu
    Copy the full SHA
    f4b9dc3 View commit details
    Browse the repository at this point in the history