rust/src/librustc_data_structures
bors f686885a14 Auto merge of #52342 - nnethercote:CanonicalVar, r=nikomatsakis
Avoid most allocations in `Canonicalizer`.

Extra allocations are a significant cost of NLL, and the most common
ones come from within `Canonicalizer`. In particular, `canonical_var()`
contains this code:

    indices
	.entry(kind)
	.or_insert_with(|| {
	    let cvar1 = variables.push(info);
	    let cvar2 = var_values.push(kind);
	    assert_eq!(cvar1, cvar2);
	    cvar1
	})
	.clone()

`variables` and `var_values` are `Vec`s. `indices` is a `HashMap` used
to track what elements have been inserted into `var_values`. If `kind`
hasn't been seen before, `indices`, `variables` and `var_values` all get
a new element. (The number of elements in each container is always the
same.) This results in lots of allocations.

In practice, most of the time these containers only end up holding a few
elements. This PR changes them to avoid heap allocations in the common
case, by changing the `Vec`s to `SmallVec`s and only using `indices`
once enough elements are present. (When the number of elements is small,
a direct linear search of `var_values` is as good or better than a
hashmap lookup.)

The changes to `variables` are straightforward and contained within
`Canonicalizer`. The changes to `indices` are more complex but also
contained within `Canonicalizer`. The changes to `var_values` are more
intrusive because they require defining a new type
`SmallCanonicalVarValues` -- which is to `CanonicalVarValues` as
`SmallVec` is to `Vec -- and passing stack-allocated values of that type
in from outside.

All this speeds up a number of NLL "check" builds, the best by 2%.

r? @nikomatsakis
2018-07-18 00:45:57 +00:00
..
graph nit: fix all_sccs comment 2018-07-13 01:29:10 -04:00
obligation_forest Reduce the number of clone()s needed in obligation_forest 2018-07-14 07:31:19 +02:00
owning_ref Enforce #![deny(bare_trait_objects)] in src/librustc_data_structures tests 2018-07-11 14:21:26 +02:00
snapshot_map Avoid repeated HashMap lookups in opt_normalize_projection_type. 2018-05-17 09:34:20 +10:00
accumulate_vec.rs Avoid most allocations in Canonicalizer. 2018-07-17 13:42:11 +10:00
array_vec.rs stabilize RangeBounds collections_range #30877 2018-05-24 05:01:40 -07:00
base_n.rs Shorten names of some compiler generated artifacts. 2018-01-08 12:30:52 +01:00
bitslice.rs Fix bitslice printing. 2018-07-13 13:05:22 +10:00
bitvec.rs Generate region values directly to reduce memory usage. 2018-07-16 23:46:14 -04:00
Cargo.toml Update Rayon version 2018-06-06 15:25:16 +02:00
flock.rs Fix definitions of ULONG_PTR 2017-05-06 15:46:16 +01:00
fx.rs get rustc_hash from external crate 2018-05-24 12:01:27 -04:00
indexed_set.rs improve comments 2018-07-02 11:40:49 -04:00
indexed_vec.rs Generate region values directly to reduce memory usage. 2018-07-16 23:46:14 -04:00
lib.rs Generate region values directly to reduce memory usage. 2018-07-16 23:46:14 -04:00
sip128.rs rustc_data_structures: Add implementation of 128 bit SipHash. 2017-10-16 14:44:40 +02:00
small_vec.rs Avoid most allocations in Canonicalizer. 2018-07-17 13:42:11 +10:00
sorted_map.rs Auto merge of #51033 - coryshrmn:master, r=dtolnay 2018-05-25 22:18:27 +00:00
stable_hasher.rs Move PROFQ_CHAN to a Session field 2018-03-09 08:04:31 +01:00
sync.rs add a missing dyn 2018-07-11 16:08:38 +02:00
tiny_list.rs Make const decoding from the incremental cache thread-safe. 2018-06-01 09:32:24 +02:00
transitive_relation.rs Make TransitiveRelation thread safe. Avoid locking by using get_mut in some cases. 2018-02-27 19:07:33 +01:00
tuple_slice.rs Add additional test cases to test all arities of tuple; And remove type suffix - i32 on integers 2016-06-11 22:31:24 +05:30
work_queue.rs create a new WorkQueue data structure 2018-07-01 05:22:50 -04:00