rust/src/librustc_data_structures
Nicholas Nethercote 7cc527770d 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%.
2018-07-17 13:42:11 +10:00
..
control_flow_graph use fmt::Result where applicable 2018-05-09 02:01:37 +02:00
graph Implement some trivial size_hints for various iterators 2018-03-20 05:33:59 -04:00
obligation_forest Improve Node::{parent,dependents} interplay. 2018-06-18 10:04:23 +10:00
owning_ref use fmt::Result where applicable 2018-05-09 02:01:37 +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 rustc_data_structures: add missing #[inline]. 2018-02-21 19:21:26 +02:00
bitvec.rs ignore the point where the outlives requirement was added 2018-05-09 23:21:24 -03: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 convert type-check constraints into NLL constraints on the fly 2018-06-09 11:02:14 -04:00
lib.rs create a new WorkQueue data structure 2018-07-01 05:22:50 -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 MTRef and a lock_mut function to MTLock 2018-06-19 03:19:50 +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