# Uninvoked logging with interpolated string screws performance

**URL:** https://discourse.julialang.org/t/uninvoked-logging-with-interpolated-string-screws-performance/123806
**Category:** Performance
**Tags:** performance, logging
**Created:** [December 13, 2024, 10:58am UTC](https://discourse.julialang.org/t/uninvoked-logging-with-interpolated-string-screws-performance/123806 "2024-12-13T10:58:23Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![dpinol](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpinol/32/26550_2.png) [@dpinol](https://discourse.julialang.org/u/dpinol)
#### Post date: [December 13, 2024, 10:58am UTC](https://discourse.julialang.org/t/uninvoked-logging-with-interpolated-string-screws-performance/123806/1 "2024-12-13T10:58:23Z")

</div>

I have a a hot loop function which merges 2 SparseVector of 1k items each.

With @benchmark I can see that adding  
`conditionWhichIsFalse && @warn lazy"msg $myIntVariable" `  
after the loop, makes the function 3 times slower (25us instead of 8us).

Converting to `conditionWhichIsFalse && @warn "msg" myIntVariable"`  
solves it.

1. Is the compiler not optimizing the function because it finds it too complex when adding the string interpolation?
2. Any best practice or tool to mitigate or diagnose this kind of problems?

thanks

---

<div class="post-metadata">

### Author: ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)
#### Post date: [December 13, 2024, 11:31am UTC](https://discourse.julialang.org/t/uninvoked-logging-with-interpolated-string-screws-performance/123806/2 "2024-12-13T11:31:26Z")

</div>

Without having checked, I think what you’re seeing is that the string from the interpolation might be constructed regardless. Or that the effects of creating a string through interpolation disable some other optimization the compiler is ordinarily able to do.

You could try using a `LazyString`?

---

<div class="post-metadata">

### Author: ![dpinol](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpinol/32/26550_2.png) [@dpinol](https://discourse.julialang.org/u/dpinol)
#### Post date: [December 13, 2024, 11:51am UTC](https://discourse.julialang.org/t/uninvoked-logging-with-interpolated-string-screws-performance/123806/3 "2024-12-13T11:51:23Z")

</div>

Sorry, I forgot to add it to my code (edited). I had tried with `lazy".."` but it didn’t help.

`@warn lazy"msg $myIntVariable"`
