harmony: A couple of points I want to make:
Don't worry about optimizing everything, code clarity is way more important in most cases. Only optimise code that is raw very often (1000+ times a second) and that is actually too slow.
The linked article has a deeply flawed approach: it only looks at the generated bytecode to determine performance, but it doesn't take into account that the JIT is able to optimize a lot of things away at runtime. For example, the article complains a lot about getters, but performance is identical to direct field accesses: https://stackoverflow.com/questions/23931546/java-getter-and-setter-faster-than-direct-access
A new article has been written that does use benchmarks, altrough @benleggiero has found that there are some wrong conclusions there too: https://sites.google.com/a/athaydes.com/renato-athaydes/posts/kotlinshiddencosts-benchmarks
I'd say you don't have to worry about companion objects most of the time 🙂
07/03/2017, 12:29 PM
what about all the calls to
in non private functions?
07/03/2017, 12:33 PM
The JIT is probably good at optimizing those away too, since it's a really common thing to do in java. Think about it: when you call a method on an object, there is always an implicit null check.