Skip to content

Commit 4563f70

Browse files
committed
Auto merge of rust-lang#122070 - Zoxc:dep-edges-from-previous, r=cjgillot
Encode dep graph edges directly from the previous graph when promoting This encodes dep graph edges directly from the previous graph when promoting nodes from a previous session, avoiding allocations / copies. ~~Based on rust-lang#122064 and rust-lang#116375 <table><tr><td rowspan="2">Benchmark</td><td colspan="1"><b>Before</b></th><td colspan="2"><b>After</b></th></tr><tr><td align="right">Time</td><td align="right">Time</td><td align="right">%</th></tr><tr><td>🟣 <b>clap</b>:check:unchanged</td><td align="right">0.4177s</td><td align="right">0.4072s</td><td align="right">💚 -2.52%</td></tr><tr><td>🟣 <b>hyper</b>:check:unchanged</td><td align="right">0.1430s</td><td align="right">0.1420s</td><td align="right"> -0.69%</td></tr><tr><td>🟣 <b>regex</b>:check:unchanged</td><td align="right">0.3106s</td><td align="right">0.3038s</td><td align="right">💚 -2.19%</td></tr><tr><td>🟣 <b>syn</b>:check:unchanged</td><td align="right">0.5823s</td><td align="right">0.5688s</td><td align="right">💚 -2.33%</td></tr><tr><td>🟣 <b>syntex_syntax</b>:check:unchanged</td><td align="right">1.3992s</td><td align="right">1.3692s</td><td align="right">💚 -2.14%</td></tr><tr><td>Total</td><td align="right">2.8528s</td><td align="right">2.7910s</td><td align="right">💚 -2.17%</td></tr><tr><td>Summary</td><td align="right">1.0000s</td><td align="right">0.9803s</td><td align="right">💚 -1.97%</td></tr></table>
2 parents d009f60 + aa9c9a3 commit 4563f70

File tree

4 files changed

+183
-45
lines changed

4 files changed

+183
-45
lines changed

compiler/rustc_incremental/src/persist/load.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use rustc_session::config::IncrementalStateAssertion;
1111
use rustc_session::Session;
1212
use rustc_span::ErrorGuaranteed;
1313
use std::path::{Path, PathBuf};
14+
use std::sync::Arc;
1415

1516
use super::data::*;
1617
use super::file_format;
@@ -88,7 +89,7 @@ fn delete_dirty_work_product(sess: &Session, swp: SerializedWorkProduct) {
8889
work_product::delete_workproduct_files(sess, &swp.work_product);
8990
}
9091

91-
fn load_dep_graph(sess: &Session) -> LoadResult<(SerializedDepGraph, WorkProductMap)> {
92+
fn load_dep_graph(sess: &Session) -> LoadResult<(Arc<SerializedDepGraph>, WorkProductMap)> {
9293
let prof = sess.prof.clone();
9394

9495
if sess.opts.incremental.is_none() {

compiler/rustc_incremental/src/persist/save.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use rustc_serialize::opaque::{FileEncodeResult, FileEncoder};
1010
use rustc_serialize::Encodable as RustcEncodable;
1111
use rustc_session::Session;
1212
use std::fs;
13+
use std::sync::Arc;
1314

1415
use super::data::*;
1516
use super::dirty_clean;
@@ -147,7 +148,7 @@ fn encode_query_cache(tcx: TyCtxt<'_>, encoder: FileEncoder) -> FileEncodeResult
147148
/// and moves it to the permanent dep-graph path
148149
pub(crate) fn build_dep_graph(
149150
sess: &Session,
150-
prev_graph: SerializedDepGraph,
151+
prev_graph: Arc<SerializedDepGraph>,
151152
prev_work_products: WorkProductMap,
152153
) -> Option<DepGraph> {
153154
if sess.opts.incremental.is_none() {

compiler/rustc_query_system/src/dep_graph/graph.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use std::fmt::Debug;
1313
use std::hash::Hash;
1414
use std::marker::PhantomData;
1515
use std::sync::atomic::Ordering;
16+
use std::sync::Arc;
1617

1718
use super::query::DepGraphQuery;
1819
use super::serialized::{GraphEncoder, SerializedDepGraph, SerializedDepNodeIndex};
@@ -81,7 +82,7 @@ pub(crate) struct DepGraphData<D: Deps> {
8182

8283
/// The dep-graph from the previous compilation session. It contains all
8384
/// nodes and edges as well as all fingerprints of nodes that have them.
84-
previous: SerializedDepGraph,
85+
previous: Arc<SerializedDepGraph>,
8586

8687
colors: DepNodeColorMap,
8788

@@ -113,7 +114,7 @@ where
113114
impl<D: Deps> DepGraph<D> {
114115
pub fn new(
115116
profiler: &SelfProfilerRef,
116-
prev_graph: SerializedDepGraph,
117+
prev_graph: Arc<SerializedDepGraph>,
117118
prev_work_products: WorkProductMap,
118119
encoder: FileEncoder,
119120
record_graph: bool,
@@ -127,6 +128,7 @@ impl<D: Deps> DepGraph<D> {
127128
encoder,
128129
record_graph,
129130
record_stats,
131+
prev_graph.clone(),
130132
);
131133

132134
let colors = DepNodeColorMap::new(prev_graph_node_count);
@@ -1084,6 +1086,7 @@ impl<D: Deps> CurrentDepGraph<D> {
10841086
encoder: FileEncoder,
10851087
record_graph: bool,
10861088
record_stats: bool,
1089+
previous: Arc<SerializedDepGraph>,
10871090
) -> Self {
10881091
use std::time::{SystemTime, UNIX_EPOCH};
10891092

@@ -1116,6 +1119,7 @@ impl<D: Deps> CurrentDepGraph<D> {
11161119
record_graph,
11171120
record_stats,
11181121
profiler,
1122+
previous,
11191123
),
11201124
new_node_to_index: Sharded::new(|| {
11211125
FxHashMap::with_capacity_and_hasher(
@@ -1236,16 +1240,14 @@ impl<D: Deps> CurrentDepGraph<D> {
12361240
match prev_index_to_index[prev_index] {
12371241
Some(dep_node_index) => dep_node_index,
12381242
None => {
1239-
let key = prev_graph.index_to_node(prev_index);
1240-
let edges = prev_graph
1241-
.edge_targets_from(prev_index)
1242-
.map(|i| prev_index_to_index[i].unwrap())
1243-
.collect();
1244-
let fingerprint = prev_graph.fingerprint_by_index(prev_index);
1245-
let dep_node_index = self.encoder.send(key, fingerprint, edges);
1243+
let dep_node_index = self.encoder.send_promoted(prev_index, &*prev_index_to_index);
12461244
prev_index_to_index[prev_index] = Some(dep_node_index);
12471245
#[cfg(debug_assertions)]
1248-
self.record_edge(dep_node_index, key, fingerprint);
1246+
self.record_edge(
1247+
dep_node_index,
1248+
prev_graph.index_to_node(prev_index),
1249+
prev_graph.fingerprint_by_index(prev_index),
1250+
);
12491251
dep_node_index
12501252
}
12511253
}

0 commit comments

Comments
 (0)