Make the fast path faster.

This commit is contained in:
Camille GILLOT 2021-05-12 08:49:49 +02:00
parent 91444af87a
commit eb82187b13
2 changed files with 15 additions and 14 deletions

View File

@ -792,7 +792,7 @@ pub fn encode(&self, profiler: &SelfProfilerRef) -> FileEncodeResult {
}
}
fn next_virtual_depnode_index(&self) -> DepNodeIndex {
pub(crate) fn next_virtual_depnode_index(&self) -> DepNodeIndex {
let index = self.virtual_dep_node_index.fetch_add(1, Relaxed);
DepNodeIndex::from_u32(index)
}

View File

@ -452,11 +452,15 @@ fn try_execute_query<CTX, C>(
}
};
// Fast path for when incr. comp. is off. `to_dep_node` is
// expensive for some `DepKind`s.
if !tcx.dep_context().dep_graph().is_fully_enabled() {
let null_dep_node = DepNode::new_no_params(DepKind::NULL);
return force_query_with_job(tcx, key, job, null_dep_node, query).0;
let dep_graph = tcx.dep_context().dep_graph();
// Fast path for when incr. comp. is off.
if !dep_graph.is_fully_enabled() {
let prof_timer = tcx.dep_context().profiler().query_provider();
let result = tcx.start_query(job.id, None, || query.compute(tcx, key));
let dep_node_index = dep_graph.next_virtual_depnode_index();
prof_timer.finish_with_query_invocation_id(dep_node_index.into());
return job.complete(result, dep_node_index);
}
if query.anon {
@ -464,17 +468,14 @@ fn try_execute_query<CTX, C>(
let ((result, dep_node_index), diagnostics) = with_diagnostics(|diagnostics| {
tcx.start_query(job.id, diagnostics, || {
tcx.dep_context().dep_graph().with_anon_task(
*tcx.dep_context(),
query.dep_kind,
|| query.compute(tcx, key),
)
dep_graph
.with_anon_task(*tcx.dep_context(), query.dep_kind, || query.compute(tcx, key))
})
});
prof_timer.finish_with_query_invocation_id(dep_node_index.into());
tcx.dep_context().dep_graph().read_index(dep_node_index);
dep_graph.read_index(dep_node_index);
if unlikely!(!diagnostics.is_empty()) {
tcx.store_diagnostics_for_anon_node(dep_node_index, diagnostics);
@ -490,7 +491,7 @@ fn try_execute_query<CTX, C>(
// promoted to the current session during
// `try_mark_green()`, so we can ignore them here.
let loaded = tcx.start_query(job.id, None, || {
let marked = tcx.dep_context().dep_graph().try_mark_green_and_read(tcx, &dep_node);
let marked = dep_graph.try_mark_green_and_read(tcx, &dep_node);
marked.map(|(prev_dep_node_index, dep_node_index)| {
(
load_from_disk_and_cache_in_memory(
@ -511,7 +512,7 @@ fn try_execute_query<CTX, C>(
}
let (result, dep_node_index) = force_query_with_job(tcx, key, job, dep_node, query);
tcx.dep_context().dep_graph().read_index(dep_node_index);
dep_graph.read_index(dep_node_index);
result
}