From b86eb2e8ba3f442a2168406fc75e1f41cdc9ccc7 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Thu, 28 Nov 2019 20:34:55 +0100 Subject: [PATCH] Some optimizations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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' --- src/base.rs | 26 ++++++++++++++------------ src/pretty_clif.rs | 12 +++++++++--- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/base.rs b/src/base.rs index 441d875ef21d..243852f1d2be 100644 --- a/src/base.rs +++ b/src/base.rs @@ -74,20 +74,22 @@ pub fn trans_fn<'clif, 'tcx, B: Backend + 'static>( context.func = func; cx.module.define_function(func_id, context).unwrap(); - let value_ranges = context - .build_value_labels_ranges(cx.module.isa()) - .expect("value location ranges"); - // Write optimized function to file for debugging #[cfg(debug_assertions)] - crate::pretty_clif::write_clif_file( - cx.tcx, - "opt", - instance, - &context.func, - &clif_comments, - Some(&value_ranges), - ); + { + let value_ranges = context + .build_value_labels_ranges(cx.module.isa()) + .expect("value location ranges"); + + crate::pretty_clif::write_clif_file( + cx.tcx, + "opt", + instance, + &context.func, + &clif_comments, + Some(&value_ranges), + ); + } // Define debuginfo for function let isa = cx.module.isa(); diff --git a/src/pretty_clif.rs b/src/pretty_clif.rs index f595d384f4f2..64359f3899f5 100644 --- a/src/pretty_clif.rs +++ b/src/pretty_clif.rs @@ -74,8 +74,8 @@ pub struct CommentWriter { impl CommentWriter { pub fn new<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> Self { - CommentWriter { - global_comments: vec![ + let mut global_comments = if cfg!(debug_assertions) { + vec![ format!("symbol {}", tcx.symbol_name(instance).name.as_str()), format!("instance {:?}", instance), format!( @@ -86,7 +86,13 @@ impl CommentWriter { ) ), String::new(), - ], + ] + } else { + vec![] + }; + + CommentWriter { + global_comments, entity_comments: HashMap::new(), inst_comments: HashMap::new(), }