Skip to content

Commit c3a28b2

Browse files
committed
Some optimizations
* Only format global _comments when debug_assertions are enabled * Only call build_value_labels_ranges in base.rs when debug_assertions are enabled Benchmark #1: CHANNEL='pre' ../cargo.sh build Time (mean ± σ): 17.657 s ± 1.050 s [User: 31.871 s, System: 3.014 s] Range (min … max): 16.907 s … 20.394 s 10 runs Benchmark #2: ../cargo.sh build Time (mean ± σ): 16.640 s ± 0.255 s [User: 30.238 s, System: 2.965 s] Range (min … max): 16.413 s … 17.186 s 10 runs Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet PC without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options. Summary '../cargo.sh build' ran 1.06 ± 0.07 times faster than 'CHANNEL='pre' ../cargo.sh build'
1 parent 065c25c commit c3a28b2

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

src/base.rs

+14-12
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,22 @@ pub fn trans_fn<'clif, 'tcx, B: Backend + 'static>(
7474
context.func = func;
7575
cx.module.define_function(func_id, context).unwrap();
7676

77-
let value_ranges = context
78-
.build_value_labels_ranges(cx.module.isa())
79-
.expect("value location ranges");
80-
8177
// Write optimized function to file for debugging
8278
#[cfg(debug_assertions)]
83-
crate::pretty_clif::write_clif_file(
84-
cx.tcx,
85-
"opt",
86-
instance,
87-
&context.func,
88-
&clif_comments,
89-
Some(&value_ranges),
90-
);
79+
{
80+
let value_ranges = context
81+
.build_value_labels_ranges(cx.module.isa())
82+
.expect("value location ranges");
83+
84+
crate::pretty_clif::write_clif_file(
85+
cx.tcx,
86+
"opt",
87+
instance,
88+
&context.func,
89+
&clif_comments,
90+
Some(&value_ranges),
91+
);
92+
}
9193

9294
// Define debuginfo for function
9395
let isa = cx.module.isa();

src/pretty_clif.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ pub struct CommentWriter {
7474

7575
impl CommentWriter {
7676
pub fn new<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> Self {
77-
CommentWriter {
78-
global_comments: vec![
77+
let mut global_comments = if cfg!(debug_assertions) {
78+
vec![
7979
format!("symbol {}", tcx.symbol_name(instance).name.as_str()),
8080
format!("instance {:?}", instance),
8181
format!(
@@ -86,7 +86,13 @@ impl CommentWriter {
8686
)
8787
),
8888
String::new(),
89-
],
89+
]
90+
} else {
91+
vec![]
92+
};
93+
94+
CommentWriter {
95+
global_comments,
9096
entity_comments: HashMap::new(),
9197
inst_comments: HashMap::new(),
9298
}

0 commit comments

Comments
 (0)