diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2018-05-10 11:35:27 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-05-10 11:35:27 -0500 |
| commit | e23ec4b6f08828dbced71779eb9b390d85f1898b (patch) | |
| tree | d2eb7ccfac60c573b57c161453a974642b7aa2c8 | |
| parent | a77ba86424cae163edf36415a2933c6a8b703ee3 (diff) | |
| parent | 78262e700dc6a7b57e376742f344e80115d2d3f2 (diff) | |
| download | rust-e23ec4b6f08828dbced71779eb9b390d85f1898b.tar.gz rust-e23ec4b6f08828dbced71779eb9b390d85f1898b.zip | |
Rollup merge of #50565 - nnethercote:try_mark_green, r=michaelwoerister
Use SmallVec for DepNodeIndex within dep_graph. This avoids a decent number of allocations, enough to speed up incremental runs of many rustc-benchmarks, the best by 2%. Here are the rustc-perf benchmarks that showed an improvement of at least 1% on one run: ``` unused-warnings-check avg: -1.7% min: -2.4% max: 0.0% unused-warnings-opt avg: -1.4% min: -2.0% max: 0.0% unused-warnings avg: -1.4% min: -2.0% max: -0.0% tokio-webpush-simple-check avg: -1.0% min: -1.7% max: 0.0% futures-opt avg: -0.9% min: -1.6% max: 0.0% encoding avg: -1.2% min: -1.6% max: -0.6% encoding-check avg: -0.9% min: -1.6% max: 0.0% encoding-opt avg: -0.8% min: -1.6% max: -0.1% futures avg: -0.9% min: -1.5% max: 0.0% futures-check avg: -0.9% min: -1.5% max: 0.1% regression-31157-check avg: -0.9% min: -1.5% max: 0.0% regex avg: -0.6% min: -1.4% max: 0.0% regression-31157-opt avg: -0.5% min: -1.4% max: 0.1% regression-31157 avg: -0.7% min: -1.4% max: 0.2% regex-opt avg: -0.6% min: -1.4% max: 0.1% hyper-check avg: -0.8% min: -1.4% max: -0.1% regex-check avg: -1.0% min: -1.4% max: 0.0% hyper-opt avg: -0.7% min: -1.4% max: -0.1% hyper avg: -0.7% min: -1.3% max: 0.1% piston-image-opt avg: -0.4% min: -1.3% max: 0.0% tokio-webpush-simple-opt avg: -0.3% min: -1.3% max: 0.0% piston-image-check avg: -0.5% min: -1.3% max: -0.0% syn-opt avg: -0.5% min: -1.3% max: 0.0% clap-rs-check avg: -0.3% min: -1.3% max: 0.2% piston-image avg: -0.5% min: -1.2% max: 0.1% syn avg: -0.5% min: -1.2% max: 0.1% syn-check avg: -0.6% min: -1.2% max: -0.1% issue-46449-opt avg: -0.4% min: -1.2% max: -0.1% parser-check avg: -0.7% min: -1.2% max: 0.1% issue-46449 avg: -0.5% min: -1.2% max: -0.0% ```
| -rw-r--r-- | src/librustc/dep_graph/graph.rs | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/librustc/dep_graph/graph.rs b/src/librustc/dep_graph/graph.rs index 61a7404b085..4efb2b61e2b 100644 --- a/src/librustc/dep_graph/graph.rs +++ b/src/librustc/dep_graph/graph.rs @@ -12,6 +12,7 @@ use errors::DiagnosticBuilder; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::indexed_vec::{Idx, IndexVec}; +use rustc_data_structures::small_vec::SmallVec; use rustc_data_structures::sync::{Lrc, RwLock, ReadGuard, Lock}; use std::env; use std::hash::Hash; @@ -132,7 +133,7 @@ impl DepGraph { let mut edges = Vec::new(); for (index, edge_targets) in current_dep_graph.edges.iter_enumerated() { let from = current_dep_graph.nodes[index]; - for &edge_target in edge_targets { + for &edge_target in edge_targets.iter() { let to = current_dep_graph.nodes[edge_target]; edges.push((from, to)); } @@ -210,7 +211,7 @@ impl DepGraph { self.with_task_impl(key, cx, arg, false, task, |key| OpenTask::Regular(Lock::new(RegularOpenTask { node: key, - reads: Vec::new(), + reads: SmallVec::new(), read_set: FxHashSet(), })), |data, key, task| data.borrow_mut().complete_task(key, task)) @@ -231,7 +232,7 @@ impl DepGraph { self.with_task_impl(key, cx, input, true, identity_fn, |_| OpenTask::Ignore, - |data, key, _| data.borrow_mut().alloc_node(key, Vec::new())) + |data, key, _| data.borrow_mut().alloc_node(key, SmallVec::new())) } fn with_task_impl<'gcx, C, A, R>( @@ -354,7 +355,7 @@ impl DepGraph { if let Some(ref data) = self.data { let (result, open_task) = ty::tls::with_context(|icx| { let task = OpenTask::Anon(Lock::new(AnonOpenTask { - reads: Vec::new(), + reads: SmallVec::new(), read_set: FxHashSet(), })); @@ -614,7 +615,7 @@ impl DepGraph { debug_assert!(data.colors.borrow().get(prev_dep_node_index).is_none()); - let mut current_deps = Vec::new(); + let mut current_deps = SmallVec::new(); for &dep_dep_node_index in prev_deps { let dep_dep_node_color = data.colors.borrow().get(dep_dep_node_index); @@ -911,7 +912,7 @@ pub enum WorkProductFileKind { pub(super) struct CurrentDepGraph { nodes: IndexVec<DepNodeIndex, DepNode>, - edges: IndexVec<DepNodeIndex, Vec<DepNodeIndex>>, + edges: IndexVec<DepNodeIndex, SmallVec<[DepNodeIndex; 8]>>, node_to_node_index: FxHashMap<DepNode, DepNodeIndex>, forbidden_edge: Option<EdgeFilter>, @@ -1049,7 +1050,7 @@ impl CurrentDepGraph { } = task { debug_assert_eq!(node, key); let krate_idx = self.node_to_node_index[&DepNode::new_no_params(DepKind::Krate)]; - self.alloc_node(node, vec![krate_idx]) + self.alloc_node(node, SmallVec::one(krate_idx)) } else { bug!("complete_eval_always_task() - Expected eval always task to be popped"); } @@ -1095,7 +1096,7 @@ impl CurrentDepGraph { fn alloc_node(&mut self, dep_node: DepNode, - edges: Vec<DepNodeIndex>) + edges: SmallVec<[DepNodeIndex; 8]>) -> DepNodeIndex { debug_assert_eq!(self.edges.len(), self.nodes.len()); debug_assert_eq!(self.node_to_node_index.len(), self.nodes.len()); @@ -1110,12 +1111,12 @@ impl CurrentDepGraph { pub struct RegularOpenTask { node: DepNode, - reads: Vec<DepNodeIndex>, + reads: SmallVec<[DepNodeIndex; 8]>, read_set: FxHashSet<DepNodeIndex>, } pub struct AnonOpenTask { - reads: Vec<DepNodeIndex>, + reads: SmallVec<[DepNodeIndex; 8]>, read_set: FxHashSet<DepNodeIndex>, } |
