If I have a constant like: ```const val DEBUG = fa...
# announcements
If I have a constant like:
Copy code
const val DEBUG = false
and then code like:
Copy code
if (DEBUG) {
  println("Addthread: $thread")
is set to false, will the `println`s be totally compiled out of the class file?
you can decompile in IntelliJ and check. even if it's not decompiled, I'd expect the JVM to very quickly optimize it out at runtime
huh. nice find!
I was curious, tried it out; simple test case showed that it was eliminated, so ran
kotlinc -Xlist-phases
and just did a quick check of the ones that looked relevant
but yeah even if the kotlin compiler didn't optimize it out, the JVM certainly will
or if you're targeting android, dx/d8 will perform this optimization, and ART on the device will also perform this optimization
Interesting, thanks for the investigation! I didn’t know about list-phases, I’ll have to play around with that. Certainly the JVM will optimise, but it’ll end up with more bytecode, string constants etc.
Probably nothing in the big scheme of things, but my OCD will sleep a little better knowing that Kotlin will take care of it 🙂
well, a bool const should take up very little overhead
Sure, I was referring to the constants etc involved in debug printing if it wasn’t optimised out.
But is this also true for legacy backend? The linked code is from the experimental ir backend.