Edoardo Luppi
06/11/2024, 10:55 AMArtem Kobzar
06/11/2024, 11:07 AMEdoardo Luppi
06/11/2024, 11:12 AMobject
as their namespace.
What I was observing with `object`s is a performance penalty given there is a VOID
check for every call, because of lazy initialization.
Surprisingly, if the object
doesn't have properties, but only functions, the initialization is eager and there isn't a VOID
check on each call. This means the performance is the same as with top-level functions.
// Eager init, no performance loss
object Example {
fun example() { ... }
}
// Lazy init, performance loss
object Example {
val prop = SomeClass()
fun example() { ... }
}
So people might be interested in knowing about this.