https://kotlinlang.org logo
Title
b

basher

03/08/2019, 11:15 PM
Will the Kotlin compiler optimize away / remove methods that were generated by declaring a class a
data class
, but ended up being unused?
🇳🇴 1
Do people think about this when deciding
data class
or
class
?
j

jw

03/08/2019, 11:20 PM
No. For one, in libraries, you can't know what APIs your consumers are going to use or whether they'll want to put your type into a map as a key.
👆 2
b

basher

03/08/2019, 11:26 PM
Makes sense. Thanks!
g

GarouDan

03/09/2019, 12:11 AM
In jvm I don’t know if this exists and could be very interesting. Either way in kotlin-js we have something similar (kotlin-dce plugin, for dead code elimination), but I don’t really know what this do.
j

jw

03/09/2019, 12:20 AM
Every platform had some sort of tree shaking you can opt in to at the leafs
g

GarouDan

03/09/2019, 12:26 AM
@jw, I don’t know. I don’t think we can’t eliminate unused code from libraries. Of course, if we are using reflection this could be a problem, but for your example, if you put a type in a map we can follow only that one that is being put and forget the other ones.
j

jw

03/09/2019, 12:28 AM
By leafs I mean leaf modules. You run DCE on JS apps. You run R8 or ProGuard for Java bytecode. You run LTO or whatever for native