Should I use inline function instead of regular fu...
# compose
k
Should I use inline function instead of regular function?
Copy code
@Composable
fun <T : FilterModel> FilterScreen(
    listResult: Result<List<T>>,
    filteredList: (list: List<T>) -> List<T>,
    onItemSelect: (T) -> Unit,
    navigate: () -> Unit
)
a
Not unless you've measured performance characteristics specific to this function that would indicate it's a better choice here
k
Doesn't having inline with lambda parameters always bring performance gains?
a
No, it's a trade-off, especially for
@Composable
functions. Composable functions already cache lambdas you create within them so that cost is paid far less often, and inline composables omit the restart mechanism. That means that anything in an inline composable changing will cause the caller of the inline composable to recompose too, which can often result in compose doing more work when things change rather than less.
Things like
Row
and
Column
are declared inline because they're often numerous and very deeply nested, and idiomatic compose code will already mean apps are declaring their own non-inline composables around the access of particular snapshot state to form appropriately granular recompose scopes
It was a carefully measured and considered tradeoff
k
Thank you for the explanation!