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:
@@ -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)?
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Creating the vcode string representation may be costly for large functions, so don't do it
|
||||||
|
// if the Debug level hasn't been statically (through features) or dynamically (through
|
||||||
|
// RUST_LOG) enabled.
|
||||||
|
if log_enabled!(Level::Debug) {
|
||||||
debug!(
|
debug!(
|
||||||
"vcode from lowering: \n{}",
|
"vcode from lowering: \n{}",
|
||||||
vcode.show_rru(Some(b.reg_universe()))
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if log_enabled!(Level::Debug) {
|
||||||
debug!(
|
debug!(
|
||||||
"vcode after regalloc: final version:\n{}",
|
"vcode after regalloc: final version:\n{}",
|
||||||
vcode.show_rru(Some(b.reg_universe()))
|
vcode.show_rru(Some(b.reg_universe()))
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Ok(vcode)
|
Ok(vcode)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user