performance-samples icon indicating copy to clipboard operation
performance-samples copied to clipboard

Benchmark for Compose

Open maxmaxandr opened this issue 2 years ago • 6 comments

How to implement microbenchmark test for compose function?

maxmaxandr avatar Jul 01 '22 16:07 maxmaxandr

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.

keyboardsurfer avatar Jul 12 '22 12:07 keyboardsurfer

Sorry for the delay here, we are working to make a sample available. I will leave this bug open.

bentrengrove avatar Nov 29 '22 23:11 bentrengrove

@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.

JanMalch avatar Feb 09 '24 15:02 JanMalch

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

bentrengrove avatar Feb 12 '24 01:02 bentrengrove

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

yschimke avatar Feb 13 '24 12:02 yschimke

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

bentrengrove avatar Feb 14 '24 00:02 bentrengrove

hey @keyboardsurfer. I noticed that you marked this as completed. Is there an officially supported approach for this? :)

LachlanMcKee avatar Sep 16 '24 13:09 LachlanMcKee