about summary refs log tree commit diff
path: root/src/test/codegen/align-struct.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-05-19 15:12:12 +0000
committerbors <bors@rust-lang.org>2020-05-19 15:12:12 +0000
commit672b272077561ca7b5027a8aff9ea2957c7d4c21 (patch)
tree3802fd229a7d61a2fe0342ae02a0d6096a7f3e87 /src/test/codegen/align-struct.rs
parent42acd9086f93fdc68a61cd79152abca77c6cd369 (diff)
parentf4b9dc31f68ff5b3dd19a22c4a3e3eefeaa0611a (diff)
downloadrust-672b272077561ca7b5027a8aff9ea2957c7d4c21.tar.gz
rust-672b272077561ca7b5027a8aff9ea2957c7d4c21.zip
Auto merge of #72227 - nnethercote:tiny-vecs-are-dumb, r=Amanieu
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, 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 #72013.
That strategy was barely ever used -- only when a `VecDeque` was grown,
oddly enough -- which is why it was removed in #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.

In theory, the change could increase memory usage, but in practice it
doesn't. It would be an unusual program where very small `Vec`s having a
capacity of 4 rather than 1 or 2 would make a difference. You'd need a
*lot* of very small `Vec`s, and/or some very small `Vec`s with very
large elements.

r? @Amanieu
Diffstat (limited to 'src/test/codegen/align-struct.rs')
0 files changed, 0 insertions, 0 deletions