Cranelift: remove logging of vcode when the log level isn't debug or more (#2755)

This logging step may be quite expensive, since logging has never been
optimized at all. Removing it is a clear win in compile times on my
machine for a large wasm module, for which parallel compilation is
lowering from 6 seconds to 1.5 seconds.

Co-authored-by: bjorn3 <bjorn3@users.noreply.github.com>
This commit is contained in:
Benjamin Bouvier
2021-03-23 16:07:32 +01:00
committed by GitHub
parent 2880dab8f8
commit 49ef2c652a

View File

@@ -5,7 +5,7 @@ use crate::machinst::*;
use crate::settings; use crate::settings;
use crate::timing; use crate::timing;
use log::debug; use log::{debug, log_enabled, Level};
use regalloc::{allocate_registers_with_opts, Algorithm, Options, PrettyPrint}; use regalloc::{allocate_registers_with_opts, Algorithm, Options, PrettyPrint};
/// Compile the given function down to VCode with allocated registers, ready /// Compile the given function down to VCode with allocated registers, ready
@@ -29,10 +29,15 @@ where
lower.lower(b)? lower.lower(b)?
}; };
debug!( // Creating the vcode string representation may be costly for large functions, so don't do it
"vcode from lowering: \n{}", // if the Debug level hasn't been statically (through features) or dynamically (through
vcode.show_rru(Some(b.reg_universe())) // RUST_LOG) enabled.
); if log_enabled!(Level::Debug) {
debug!(
"vcode from lowering: \n{}",
vcode.show_rru(Some(b.reg_universe()))
);
}
// Perform register allocation. // Perform register allocation.
let (run_checker, algorithm) = match vcode.flags().regalloc() { let (run_checker, algorithm) = match vcode.flags().regalloc() {
@@ -101,10 +106,12 @@ where
vcode.replace_insns_from_regalloc(result); vcode.replace_insns_from_regalloc(result);
} }
debug!( if log_enabled!(Level::Debug) {
"vcode after regalloc: final version:\n{}", debug!(
vcode.show_rru(Some(b.reg_universe())) "vcode after regalloc: final version:\n{}",
); vcode.show_rru(Some(b.reg_universe()))
);
}
Ok(vcode) Ok(vcode)
} }