Skip to content

Commit 681f2f8

Browse files
authored
Rollup merge of rust-lang#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% ```
2 parents d709eff + 78262e7 commit 681f2f8

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/librustc/dep_graph/graph.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use errors::DiagnosticBuilder;
1212
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
1313
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1414
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
15+
use rustc_data_structures::small_vec::SmallVec;
1516
use rustc_data_structures::sync::{Lrc, RwLock, ReadGuard, Lock};
1617
use std::env;
1718
use std::hash::Hash;
@@ -132,7 +133,7 @@ impl DepGraph {
132133
let mut edges = Vec::new();
133134
for (index, edge_targets) in current_dep_graph.edges.iter_enumerated() {
134135
let from = current_dep_graph.nodes[index];
135-
for &edge_target in edge_targets {
136+
for &edge_target in edge_targets.iter() {
136137
let to = current_dep_graph.nodes[edge_target];
137138
edges.push((from, to));
138139
}
@@ -210,7 +211,7 @@ impl DepGraph {
210211
self.with_task_impl(key, cx, arg, false, task,
211212
|key| OpenTask::Regular(Lock::new(RegularOpenTask {
212213
node: key,
213-
reads: Vec::new(),
214+
reads: SmallVec::new(),
214215
read_set: FxHashSet(),
215216
})),
216217
|data, key, task| data.borrow_mut().complete_task(key, task))
@@ -231,7 +232,7 @@ impl DepGraph {
231232

232233
self.with_task_impl(key, cx, input, true, identity_fn,
233234
|_| OpenTask::Ignore,
234-
|data, key, _| data.borrow_mut().alloc_node(key, Vec::new()))
235+
|data, key, _| data.borrow_mut().alloc_node(key, SmallVec::new()))
235236
}
236237

237238
fn with_task_impl<'gcx, C, A, R>(
@@ -354,7 +355,7 @@ impl DepGraph {
354355
if let Some(ref data) = self.data {
355356
let (result, open_task) = ty::tls::with_context(|icx| {
356357
let task = OpenTask::Anon(Lock::new(AnonOpenTask {
357-
reads: Vec::new(),
358+
reads: SmallVec::new(),
358359
read_set: FxHashSet(),
359360
}));
360361

@@ -614,7 +615,7 @@ impl DepGraph {
614615

615616
debug_assert!(data.colors.borrow().get(prev_dep_node_index).is_none());
616617

617-
let mut current_deps = Vec::new();
618+
let mut current_deps = SmallVec::new();
618619

619620
for &dep_dep_node_index in prev_deps {
620621
let dep_dep_node_color = data.colors.borrow().get(dep_dep_node_index);
@@ -911,7 +912,7 @@ pub enum WorkProductFileKind {
911912

912913
pub(super) struct CurrentDepGraph {
913914
nodes: IndexVec<DepNodeIndex, DepNode>,
914-
edges: IndexVec<DepNodeIndex, Vec<DepNodeIndex>>,
915+
edges: IndexVec<DepNodeIndex, SmallVec<[DepNodeIndex; 8]>>,
915916
node_to_node_index: FxHashMap<DepNode, DepNodeIndex>,
916917
forbidden_edge: Option<EdgeFilter>,
917918

@@ -1049,7 +1050,7 @@ impl CurrentDepGraph {
10491050
} = task {
10501051
debug_assert_eq!(node, key);
10511052
let krate_idx = self.node_to_node_index[&DepNode::new_no_params(DepKind::Krate)];
1052-
self.alloc_node(node, vec![krate_idx])
1053+
self.alloc_node(node, SmallVec::one(krate_idx))
10531054
} else {
10541055
bug!("complete_eval_always_task() - Expected eval always task to be popped");
10551056
}
@@ -1095,7 +1096,7 @@ impl CurrentDepGraph {
10951096

10961097
fn alloc_node(&mut self,
10971098
dep_node: DepNode,
1098-
edges: Vec<DepNodeIndex>)
1099+
edges: SmallVec<[DepNodeIndex; 8]>)
10991100
-> DepNodeIndex {
11001101
debug_assert_eq!(self.edges.len(), self.nodes.len());
11011102
debug_assert_eq!(self.node_to_node_index.len(), self.nodes.len());
@@ -1110,12 +1111,12 @@ impl CurrentDepGraph {
11101111

11111112
pub struct RegularOpenTask {
11121113
node: DepNode,
1113-
reads: Vec<DepNodeIndex>,
1114+
reads: SmallVec<[DepNodeIndex; 8]>,
11141115
read_set: FxHashSet<DepNodeIndex>,
11151116
}
11161117

11171118
pub struct AnonOpenTask {
1118-
reads: Vec<DepNodeIndex>,
1119+
reads: SmallVec<[DepNodeIndex; 8]>,
11191120
read_set: FxHashSet<DepNodeIndex>,
11201121
}
11211122

0 commit comments

Comments
 (0)