Normally, when you add
inline to a method that doesn’t contain any lambda parameters, you get the following compiler warning:
[NOTHING_TO_INLINE] Expected performance impact from inlining is insignificant. Inlining works best for functions with parameters of functional types
However, within the Kotlin standard library, we can see that some methods that violate this rule are inlined, such as:
public inline operator fun <T> Lazy<T>.getValue(thisRef: Any?, property: KProperty<*>): T = value public inline fun <T> listOf(): List<T> = emptyList() public inline fun <T> mutableListOf(): MutableList<T> = ArrayList()
These are usually methods that only make a single further method call, so there’s no expected increase in code size at the call point, and it makes sense to inline them despite the lack of lambdas. (In the case of
getValue, it also allows the caller to know that the arguments are unused, which may further help performance in Kotlin 1.4.) However, why doesn’t the compiler recognize this fact and suppress the warning in these cases?
I work on an app in which the APK size is a serious concern where every KB counts, so unless the compiler is already automatically inlining these calls, being slightly more liberal with our use of
inline may help, but I’m hesitant to do so while the compiler complains.