File tree Expand file tree Collapse file tree 1 file changed +10
-0
lines changed
Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -553,6 +553,16 @@ fn gen_block(
553553 )
554554 } else {
555555 quote_spanned ! ( block. span( ) =>
556+ // These variables are left uninitialized and initialized only
557+ // if the tracing level is statically enabled at this point.
558+ // While the tracing level is also checked at span creation
559+ // time, that will still create a dummy span, and a dummy guard
560+ // and drop the dummy guard later. By lazily initializing these
561+ // variables, Rust will generate a drop flag for them and thus
562+ // only drop the guard if it was created. This creates code that
563+ // is very straightforward for LLVM to optimize out if the tracing
564+ // level is statically disabled, while not causing any performance
565+ // regression in case the level is enabled.
556566 let __tracing_attr_span;
557567 let __tracing_attr_guard;
558568 if tracing:: level_enabled!( #level) {
You can’t perform that action at this time.
0 commit comments