Skip to content

Commit e33e2d6

Browse files
committed
Attempt to reduce perf impact.
1 parent 87644d8 commit e33e2d6

File tree

1 file changed

+17
-10
lines changed
  • compiler/rustc_query_system/src/dep_graph

1 file changed

+17
-10
lines changed

compiler/rustc_query_system/src/dep_graph/graph.rs

+17-10
Original file line numberDiff line numberDiff line change
@@ -676,28 +676,35 @@ impl<K: DepKind> DepGraph<K> {
676676
None => {}
677677
}
678678

679-
let mut stack =
680-
MarkingStack { stack: vec![prev_index], sess: qcx.dep_context().sess(), graph: data };
679+
let mut stack = smallvec![prev_index];
680+
let _backtrace_print =
681+
MarkingStack { stack: &mut stack, sess: qcx.dep_context().sess(), graph: data };
681682

682683
// This DepNode and the corresponding query invocation existed
683684
// in the previous compilation session too, so we can try to
684685
// mark it as green by recursively marking all of its
685686
// dependencies green.
686-
return self
687-
.try_mark_previous_green(qcx, data, prev_index, &dep_node, &mut stack.stack)
687+
let ret = self
688+
.try_mark_previous_green(qcx, data, prev_index, &dep_node, _backtrace_print.stack)
688689
.map(|dep_node_index| (prev_index, dep_node_index));
689690

691+
// We succeeded, no backtrace.
692+
std::mem::forget(_backtrace_print);
693+
return ret;
694+
690695
/// Remember the stack of queries we are forcing in the event of an incr. comp. panic.
691-
struct MarkingStack<'a, K: DepKind> {
692-
stack: Vec<SerializedDepNodeIndex>,
696+
struct MarkingStack<'a, 'v, K: DepKind> {
697+
stack: &'v mut SmallVec<[SerializedDepNodeIndex; 8]>,
693698
sess: &'a rustc_session::Session,
694699
graph: &'a DepGraphData<K>,
695700
}
696701

697-
impl<'a, K: DepKind> Drop for MarkingStack<'a, K> {
702+
impl<'a, 'v, K: DepKind> Drop for MarkingStack<'a, 'v, K> {
698703
/// Print the forcing backtrace.
704+
#[inline(never)]
705+
#[cold]
699706
fn drop(&mut self) {
700-
for &frame in self.stack.iter().skip(1).rev() {
707+
for &frame in self.stack.iter().rev() {
701708
let node = self.graph.previous.index_to_node(frame);
702709
// Do not try to rely on DepNode's Debug implementation,
703710
// since it may panic.
@@ -721,7 +728,7 @@ impl<K: DepKind> DepGraph<K> {
721728
data: &DepGraphData<K>,
722729
parent_dep_node_index: SerializedDepNodeIndex,
723730
dep_node: &DepNode<K>,
724-
stack: &mut Vec<SerializedDepNodeIndex>,
731+
stack: &mut SmallVec<[SerializedDepNodeIndex; 8]>,
725732
) -> Option<()> {
726733
let dep_dep_node_color = data.colors.get(parent_dep_node_index);
727734
let dep_dep_node = &data.previous.index_to_node(parent_dep_node_index);
@@ -810,7 +817,7 @@ impl<K: DepKind> DepGraph<K> {
810817
data: &DepGraphData<K>,
811818
prev_dep_node_index: SerializedDepNodeIndex,
812819
dep_node: &DepNode<K>,
813-
stack: &mut Vec<SerializedDepNodeIndex>,
820+
stack: &mut SmallVec<[SerializedDepNodeIndex; 8]>,
814821
) -> Option<DepNodeIndex> {
815822
#[cfg(not(parallel_compiler))]
816823
{

0 commit comments

Comments
 (0)