diff options
| author | Nicholas Nethercote <nnethercote@mozilla.com> | 2020-05-18 05:28:14 +1000 |
|---|---|---|
| committer | Nicholas Nethercote <nnethercote@mozilla.com> | 2020-05-18 15:26:59 +1000 |
| commit | f4b9dc31f68ff5b3dd19a22c4a3e3eefeaa0611a (patch) | |
| tree | 220333f3e17ca191049db0304986f498ad46ae71 /src/test/codegen/align-struct.rs | |
| parent | 34cce58d81f006a5406fcae918db4492e6cf2784 (diff) | |
| download | rust-f4b9dc31f68ff5b3dd19a22c4a3e3eefeaa0611a.tar.gz rust-f4b9dc31f68ff5b3dd19a22c4a3e3eefeaa0611a.zip | |
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 #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.
Diffstat (limited to 'src/test/codegen/align-struct.rs')
0 files changed, 0 insertions, 0 deletions
