performance-samples
performance-samples copied to clipboard
Benchmark for Compose
How to implement microbenchmark test for compose function?
Passing this over to @bentrengrove. AFAICT we don't have a specific microbenchmark with Compose somewhere in our repo at the moment. I'd be up for having it in here though.
Sorry for the delay here, we are working to make a sample available. I will leave this bug open.
@bentrengrove Is there an update for this or should one just use Macrobenchmarks?
Specifically, I'm curious about the CPU / memory consumption of Canvas + ImageVector
vs Canvas + ImageBitmap
.
There are issues we are working on that make the results from Microbenchmark used with Compose unstable and thus not really reliable, mainly around how long it takes to stabilise the JIT compilation. Once those are resolved we will make a sample for microbenchmark and Compose.
You could use Macrobenchmark for your question with a memory metric. It can be hard to differentiate from the noise but one technique is to just test a large number of the composable at the same time. So you could compose 50 Canvas + ImageVector
composables and compare that to 50 Canvas + ImageBitmap composables
. This should hopefully override any noise coming from the unrelated parts of the code that would be pulled into a macrobenchmark
Is there anything from Androidx that would be a good sample? or a good support library?
https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/benchmark-utils/src/main/java/androidx/compose/testutils/benchmark/ComposeBenchmarkRule.kt
That's what we are working on. The AndroidX version uses a lot of internal APIs, no commitment but its our goal to bring this feature set to everyone
hey @keyboardsurfer. I noticed that you marked this as completed. Is there an officially supported approach for this? :)