Skip to content

Commit f1a4c10

Browse files
committed
Rollup merge of #50246 - nnethercote:no-dump_allocs, r=Mark-Simulacrum
Make dump_{alloc,allocs,local}() no-ops when tracing is disabled. Because they traverse data structures and build up strings, which is wasted effort if those strings aren't printed. The patch also removes some now-unnecessary log_enabled! tests at call sites. This is a big win for the Debug and Opt runs of coercions, tuple-stress, html5ever, and encoding. ``` coercions-opt avg: -7.8% min: -14.8% max: 0.1% coercions avg: -8.0% min: -12.8% max: 0.1% tuple-stress avg: -7.2% min: -10.8% max: -0.7% tuple-stress-opt avg: -6.9% min: -10.7% max: 0.6% html5ever avg: -4.6% min: -7.3% max: -0.3% encoding avg: -2.4% min: -4.5% max: 0.1% html5ever-opt avg: -2.7% min: -4.2% max: -0.2% encoding-opt avg: -1.4% min: -2.4% max: 0.0% ```
2 parents e9b67d2 + 2e4f66a commit f1a4c10

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

src/librustc_mir/interpret/eval_context.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -768,9 +768,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
768768
}
769769
}
770770

771-
if log_enabled!(::log::Level::Trace) {
772-
self.dump_local(dest);
773-
}
771+
self.dump_local(dest);
774772

775773
Ok(())
776774
}
@@ -1572,6 +1570,9 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
15721570

15731571
pub fn dump_local(&self, place: Place) {
15741572
// Debug output
1573+
if !log_enabled!(::log::Level::Trace) {
1574+
return;
1575+
}
15751576
match place {
15761577
Place::Local { frame, local } => {
15771578
let mut allocs = Vec::new();

src/librustc_mir/interpret/memory.rs

+6
Original file line numberDiff line numberDiff line change
@@ -334,11 +334,17 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
334334

335335
/// For debugging, print an allocation and all allocations it points to, recursively.
336336
pub fn dump_alloc(&self, id: AllocId) {
337+
if !log_enabled!(::log::Level::Trace) {
338+
return;
339+
}
337340
self.dump_allocs(vec![id]);
338341
}
339342

340343
/// For debugging, print a list of allocations and all allocations they point to, recursively.
341344
pub fn dump_allocs(&self, mut allocs: Vec<AllocId>) {
345+
if !log_enabled!(::log::Level::Trace) {
346+
return;
347+
}
342348
use std::fmt::Write;
343349
allocs.sort();
344350
allocs.dedup();

src/librustc_mir/interpret/place.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
219219
}
220220
};
221221

222-
if log_enabled!(::log::Level::Trace) {
223-
self.dump_local(place);
224-
}
222+
self.dump_local(place);
225223

226224
Ok(place)
227225
}

0 commit comments

Comments
 (0)