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

Gagan Deep

02/22/2022, 3:47 PM
Hello!! Is there a way to measure the rendering time of Composables, or what is equivalent of
onGlobalLayout
in Compose world?
@Will Shelor any thoughts!! I have gone through your article https://engineering.premise.com/measuring-render-performance-with-jetpack-compose-c0bf5814933 but we are not using any Fragments, so cant use
onResume
to measure when view is rendered
w

Will Shelor

02/23/2022, 3:40 PM
Sure! onGlobalLayout is still called with Compose with basically the same timing as the view world
But if you want to get more accurate, Perfetto and the Android Studio profiler are probably the way to go. If you haven’t used it, Perfetto gives you very accurate real-world data from more recent devices. Using it, you can pretty easily look at your composition from a higher level and see how long your rendering is taking, what is taking so much time, and whether jit compilation is happening. (jit compilation will be slightly better on production devices because the play store will download profiles for your most commonly used code)
g

Gagan Deep

02/23/2022, 3:48 PM
ok, i will give it a try, but my use-case is slightly different, we want to calculate page-rendering time and send it for analytics, and our pages are composables 🙂 , so was figuring how to measure the render time
w

Will Shelor

02/23/2022, 3:48 PM
if you want more specifics as to what is taking up so much time in your perfetto profile, I’ve also had luck with the Android Studio profiler. You can sample method traces, which allows you to see exactly what is happening with a ton of detail- but it also completely messes that performance up, meaning that what you’re seeing is not that accurate
Ah! Calculating it in the wild is a much more difficult problem. It’s a problem in XML too, as both recyclerviews and lazycolumns can cause onGlobalLayout to call multiple times
g

Gagan Deep

02/23/2022, 3:50 PM
yes, thats what i am struggling at, i tried using
LaunchedEffect
to calculate as it is called one time during composition
but the numbers are not correct
w

Will Shelor

02/23/2022, 3:52 PM
onGlobalLayout should be just as accurate as it was with XML. In my testing I saw it firing twice, once for the base layout and once for the recyclerview- with the same being true for both xml and Compose
👍 1
https://developer.android.com/studio/profile/jankstats this library released the other day, I wonder if it could provide any tools?
g

Gagan Deep

02/23/2022, 3:54 PM
ok.. thanks for the info, i will take look 🙂
w

Will Shelor

02/23/2022, 3:54 PM
The problem with measuring something like rendering is that the system renders a lot, for a lot of reasons, so it’s not really a one-time thing; but what we want to measure here is something more specific. IMO it makes a great microbenchmarking/macrobenchmarking test, but it’s hard to do in the wild.
g

Gagan Deep

02/23/2022, 3:57 PM
you are right, its more suitable for macrobenchmarking
ohhk, thanks for the advice 👍
7 Views