Has there been any progress towards inlining array...
# language-proposals
d
Has there been any progress towards inlining arrays of lambdas? I'm currently converting much Java code to Kotlin code and trying to simplify it, and I've run into a few cases of `Comparable`s that are just comparing a few different fields in order. Currently, I can write:
Copy code
override fun compareTo(other: Item): Int {
    return compareValuesBy(this, other, { foo }, { bar })
}
The version that takes one argument is `inline`:
Copy code
@kotlin.internal.InlineOnly
public inline fun <T> compareValuesBy(a: T, b: T, selector: (T) -> Comparable<*>?): Int {
    return compareValues(selector(a), selector(b))
}
but the one that takes a variable number is not:
Copy code
public fun <T> compareValuesBy(a: T, b: T, vararg selectors: (T) -> Comparable<*>?): Int {
    require(selectors.size > 0)
    return compareValuesByImpl(a, b, selectors)
}
This makes it considerably less efficient. This could be solved by just adding different
compareValuesBy
methods with different lambda counts to stdlib, but the more forward-thinking approach is to inline the lambdas and unroll the loop on the array. I tried searching for the topic, and found only my own post from 2020, which included a performance test demonstrating that inlining is faster. I haven't found any other progress on it, is this something on the Kotlin roadmap? https://discuss.kotlinlang.org/t/inlining-arrays-of-lambdas/18249
y
I recalled reading an issue by Roman ages ago about this. Went on a Youtrack hunt for it, and to my surprise, it literally cites
compareValuesBy
as a motivating example! https://youtrack.jetbrains.com/issue/KT-20445/Support-inline-varargs-of-functional-types-and-properties
d
Thanks! Good to see there's a ticket for it, less good to see that it's 6 years old with no progress noted yet.