rust/src/liballoc
bors 672b272077 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
2020-05-19 15:12:12 +00:00
..
alloc liballoc tests: Miri supports threads now 2020-05-01 11:16:38 +02:00
benches Introduce BTreeMap benches of iter itself 2020-04-25 00:05:10 +02:00
collections Auto merge of #71321 - matthewjasper:alloc-min-spec, r=sfackler 2020-05-14 23:22:47 +00:00
prelude Format liballoc with rustfmt 2019-11-29 20:25:07 -08:00
raw_vec Tiny Vecs are dumb. 2020-05-18 15:26:59 +10:00
rc Format the world 2019-12-22 17:42:47 -05:00
sync fix test_weak_count_locked for Miri 2020-05-11 16:49:36 +02:00
tests Auto merge of #72227 - nnethercote:tiny-vecs-are-dumb, r=Amanieu 2020-05-19 15:12:12 +00:00
alloc.rs Stop importing integer modules in liballoc 2020-04-05 11:22:01 +02:00
borrow.rs Format the world 2019-12-22 17:42:47 -05:00
boxed.rs Auto merge of #71447 - cuviper:unsized_cow, r=dtolnay 2020-05-19 08:08:48 +00:00
Cargo.toml bump rand to fix Miri failures 2019-08-04 14:50:26 +02:00
fmt.rs grammar: dealing-with 2020-05-06 19:01:27 -04:00
lib.rs Auto merge of #71321 - matthewjasper:alloc-min-spec, r=sfackler 2020-05-14 23:22:47 +00:00
macros.rs make vec![,] uncompilable 2020-04-14 10:27:55 +03:00
raw_vec.rs Tiny Vecs are dumb. 2020-05-18 15:26:59 +10:00
rc.rs Auto merge of #71447 - cuviper:unsized_cow, r=dtolnay 2020-05-19 08:08:48 +00:00
slice.rs Explain why we shouldn't add inline attr to into_vec 2020-04-19 01:03:43 +09:00
str.rs Replace max/min_value() with MAX/MIN assoc consts 2020-04-03 09:33:10 +02:00
string.rs More diagnostic items for Clippy usage 2020-04-22 07:57:56 +02:00
sync.rs Auto merge of #71447 - cuviper:unsized_cow, r=dtolnay 2020-05-19 08:08:48 +00:00
task.rs Add Arc::{incr,decr}_strong_count 2020-05-07 17:18:25 +02:00
tests.rs Stop importing integer modules in liballoc 2020-04-05 11:22:01 +02:00
vec.rs Auto merge of #71321 - matthewjasper:alloc-min-spec, r=sfackler 2020-05-14 23:22:47 +00:00