https://kotlinlang.org logo
#compose
Title
# compose
a

Ale Stamato

03/21/2024, 10:34 AM
Hey there folks, Yesterday I built an app with a macrobenchmark test to compare the performance of
ContextualFlowRow
vs an inhouse solution we built few months ago, here are the preliminary results: In house implementation results:
Copy code
ScrollBenchmark_scroll
frameDurationCpuMs  P50   6.7,   P90   8.4,   P95   8.9,   P99  10.6
frameOverrunMs      P50  -7.5,   P90  -6.1,   P95  -5.4,   P99  -3.2
ContextualFlowRow results:
Copy code
ScrollBenchmark_scroll
frameDurationCpuMs   P50   6.8,   P90  12.6,   P95  14.4,   P99  18.7
frameOverrunMs       P50  -6.6,   P90  -1.0,   P95   1.0,   P99   7.5
I sort of expected worse performance for
ContextualFlowRow
assuming it's using
SubcomposeLayout
. Should I be concerned with these numbers? Maybe there's optimisations to be done? I can share the code if ye are interested, it has some proprietary code so i didnt want to really upload to public github cc @uchennafokoye @Uchenna Okoye @jossiwolf TY
👋 1
image.png
c

Colton Idle

03/21/2024, 10:39 AM
nice finds! that reminds me... i need to try the new flowRow stuff instead of our custom impl since they added the new feature that lets you do the +6 thing in the image above.
a

Ale Stamato

03/21/2024, 10:41 AM
The new
ContextualFlowRow
is so easy to use it's absurd, this is all the code you need to achieve smth like that:
Copy code
ContextualFlowRow(
    itemCount = labels.size,
    maxLines = 2,
    overflow = ContextualFlowRowOverflow.expandIndicator {
        val count = this.totalItemCount - shownItemCount
        Text("+ $count")
    }
) {
    val index: Int = it
    val label = labels[index]
    HSLabel(text = label.text, style = label.style, maxLines = 1)
}
🌟 3
c

Colton Idle

03/21/2024, 10:51 AM
Love to see it! (i think i filed a bug on this, as well as other people) so its nice to see it come to life ❤️
j

jossiwolf

03/21/2024, 3:59 PM
I think these numbers are in line with what I'd expect, especially if your in-house solution is not using subcomposition.
Should I be concerned with these numbers?
Only if they cause issues in your benchmarks 🙂 But yeah would appreciate if you could share the code, and method traces if you can share any with us
u

Uchenna Okoye

03/21/2024, 4:58 PM
Glad to hear this positive feedback! ContextualFlowRow only composes items it renders so that helps in its performance. In that case it can be faster than Layout if the maxLines is small compared to the number of items available to render. This helps in performance to offset the other performance downsides of Subcompose.
1
a

Ale Stamato

03/21/2024, 5:16 PM
Ah gotcha. I can play with the params, and measure what happens if my element count tends to a huge number. In my case in production my element count is 10 tops with MAX_LINES = 2. I think this will always result in a worse performance than just composing everything and see what fits.
2
6 Views