https://kotlinlang.org logo
Title
d

dalexander

08/09/2018, 11:56 AM
The simplest guideline is to not inline anything unless it’s something the compiler needs or the IDE suggests. ie. if you are using generic reification you will need to inline that method. The JVM JIT is pretty good about figuring out what to inline, and unless you are very careful inline methods are more likely to hurt performance than help.
👍🏻 4
k

karelpeeters

08/09/2018, 12:29 PM
If you have small functions and they take lambda parameters make sure to inline them though, those do make a big difference.
e

elect

08/09/2018, 1:56 PM
how can inline hurt performances?
k

karelpeeters

08/09/2018, 1:58 PM
Increase code size which is bad for caching, and it duplicates code making the JVM and JIT do double work compiling and optimizing it.
d

dalexander

08/09/2018, 2:02 PM
Not only that but the JIT will only inline functions of up to a certain size, and inlining is a requirement to perform certain other optimizations, and I believe it won’t do much at all if a function is over a certain size. Big functions are bad for the JIT.