Make compose time difference larger between content types for DifferentTypesListScrollBenchmark
After the change content type 1 has 3x-4x compose time comparing to content type 0, for example
AvgComposationTimeNanos for contentType 0 is 1,905,357
AvgMeasureTimeNanos for contentType 0 is 995,121
AvgComposationTimeNanos for contentType 1 is 7,849,374
AvgMeasureTimeNanos for contentType 1 is 1,243,164
Test: Run DifferentTypesListScrollBenchmark
Change-Id: Id8181d6d46a43d1f5b1ec1a4d0f79ee3a4a19dee
diff --git a/compose/integration-tests/macrobenchmark-target/src/main/java/androidx/compose/integration/macrobenchmark/target/DifferentTypesListActivity.kt b/compose/integration-tests/macrobenchmark-target/src/main/java/androidx/compose/integration/macrobenchmark/target/DifferentTypesListActivity.kt
index 89d8de3..1e80c0e 100644
--- a/compose/integration-tests/macrobenchmark-target/src/main/java/androidx/compose/integration/macrobenchmark/target/DifferentTypesListActivity.kt
+++ b/compose/integration-tests/macrobenchmark-target/src/main/java/androidx/compose/integration/macrobenchmark/target/DifferentTypesListActivity.kt
@@ -17,21 +17,43 @@
package androidx.compose.integration.macrobenchmark.target
import android.os.Bundle
+import android.view.Choreographer
+import android.view.View
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
+import androidx.compose.foundation.Image
+import androidx.compose.foundation.border
+import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.lazy.LazyColumn
+import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.material.Card
import androidx.compose.material.Checkbox
+import androidx.compose.material.DropdownMenu
+import androidx.compose.material.Icon
+import androidx.compose.material.IconButton
import androidx.compose.material.Text
+import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.filled.MoreVert
+import androidx.compose.material3.DropdownMenuItem
import androidx.compose.runtime.Composable
+import androidx.compose.runtime.Recomposer
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.remember
+import androidx.compose.runtime.setValue
+import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.res.painterResource
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
+import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
@@ -43,7 +65,9 @@
setContent {
LazyColumn(
- modifier = Modifier.fillMaxWidth().semantics { contentDescription = "IamLazy" }
+ modifier = Modifier
+ .fillMaxWidth()
+ .semantics { contentDescription = "IamLazy" }
) {
items(count = itemCount, key = { it }, contentType = { it % 2 }) {
if (it % 2 == 0) {
@@ -58,6 +82,21 @@
launchIdlenessTracking()
}
+ internal fun ComponentActivity.launchIdlenessTracking() {
+ val contentView: View = findViewById(android.R.id.content)
+ val callback: Choreographer.FrameCallback = object : Choreographer.FrameCallback {
+ override fun doFrame(frameTimeNanos: Long) {
+ if (Recomposer.runningRecomposers.value.any { it.hasPendingWork }) {
+ contentView.contentDescription = "COMPOSE-BUSY"
+ } else {
+ contentView.contentDescription = "COMPOSE-IDLE"
+ }
+ Choreographer.getInstance().postFrameCallback(this)
+ }
+ }
+ Choreographer.getInstance().postFrameCallback(callback)
+ }
+
companion object {
const val EXTRA_ITEM_COUNT = "ITEM_COUNT"
}
@@ -65,18 +104,69 @@
@Composable
private fun OddItem(index: Int) {
- Card(modifier = Modifier.padding(8.dp)) {
- Row {
- Text(
- text = "Odd item $index",
- modifier = Modifier.padding(16.dp)
- )
- Spacer(modifier = Modifier.weight(1f, fill = true))
- Checkbox(
- checked = false,
- onCheckedChange = {},
- modifier = Modifier.padding(16.dp)
- )
+ Card(modifier = Modifier
+ .padding(8.dp)
+ .fillMaxWidth()) {
+ Column {
+ Row(verticalAlignment = Alignment.CenterVertically) {
+ Text(
+ text = "Odd item $index",
+ fontStyle = FontStyle.Italic,
+ modifier = Modifier.padding(16.dp)
+ )
+ Spacer(modifier = Modifier.weight(1f, fill = true))
+ Checkbox(
+ checked = false,
+ onCheckedChange = {},
+ modifier = Modifier.padding(16.dp)
+ )
+ }
+ Row {
+ LazyRow {
+ items(10) {
+ Image(
+ painter = painterResource(id = R.drawable.ic_launcher),
+ contentDescription = "ic launcher",
+ modifier = Modifier
+ .padding(8.dp)
+ .border(2.dp, Color.White)
+ .padding(8.dp)
+ .border(2.dp, Color.Green)
+ .padding(8.dp)
+ )
+ }
+ }
+ }
+ Row(verticalAlignment = Alignment.CenterVertically) {
+
+ var expanded by remember { mutableStateOf(false) }
+ Box(
+ modifier = Modifier
+ .fillMaxWidth()
+ .wrapContentSize(Alignment.TopEnd)
+ ) {
+ IconButton(onClick = { expanded = !expanded }) {
+ Icon(
+ imageVector = Icons.Default.MoreVert,
+ contentDescription = "More"
+ )
+ }
+
+ DropdownMenu(
+ expanded = expanded,
+ onDismissRequest = { expanded = false }
+ ) {
+ DropdownMenuItem(
+ text = { Text("Load") },
+ onClick = {}
+ )
+ DropdownMenuItem(
+ text = { Text("Save") },
+ onClick = {}
+ )
+ }
+ }
+ }
}
}
}
@@ -84,7 +174,6 @@
@Composable
private fun EvenItem(index: Int) {
Column(modifier = Modifier.padding(16.dp)) {
- Text(text = "Even item title $index", fontSize = 17.sp)
- Text(text = "Even item description")
+ Text(text = "Even item $index", fontSize = 17.sp)
}
}
diff --git a/compose/integration-tests/macrobenchmark/src/main/java/androidx/compose/integration/macrobenchmark/DifferentTypesListScrollBenchmark.kt b/compose/integration-tests/macrobenchmark/src/main/java/androidx/compose/integration/macrobenchmark/DifferentTypesListScrollBenchmark.kt
index 624bd7a..8b0db3d 100644
--- a/compose/integration-tests/macrobenchmark/src/main/java/androidx/compose/integration/macrobenchmark/DifferentTypesListScrollBenchmark.kt
+++ b/compose/integration-tests/macrobenchmark/src/main/java/androidx/compose/integration/macrobenchmark/DifferentTypesListScrollBenchmark.kt
@@ -19,6 +19,8 @@
import android.content.Intent
import android.graphics.Point
import androidx.benchmark.macro.CompilationMode
+import androidx.benchmark.macro.ExperimentalMetricApi
+import androidx.benchmark.macro.FrameTimingGfxInfoMetric
import androidx.benchmark.macro.FrameTimingMetric
import androidx.benchmark.macro.junit4.MacrobenchmarkRule
import androidx.test.filters.LargeTest
@@ -26,18 +28,12 @@
import androidx.test.uiautomator.By
import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.Until
-import androidx.testutils.createCompilationParams
import org.junit.Before
import org.junit.Rule
import org.junit.Test
-import org.junit.runner.RunWith
-import org.junit.runners.Parameterized
@LargeTest
-@RunWith(Parameterized::class)
-class DifferentTypesListScrollBenchmark(
- private val compilationMode: CompilationMode
-) {
+class DifferentTypesListScrollBenchmark {
@get:Rule
val benchmarkRule = MacrobenchmarkRule()
@@ -49,12 +45,13 @@
device = UiDevice.getInstance(instrumentation)
}
+ @OptIn(ExperimentalMetricApi::class)
@Test
fun start() {
benchmarkRule.measureRepeated(
packageName = PACKAGE_NAME,
- metrics = listOf(FrameTimingMetric()),
- compilationMode = compilationMode,
+ metrics = listOf(FrameTimingMetric(), FrameTimingGfxInfoMetric()),
+ compilationMode = CompilationMode.Full(),
iterations = 10,
setupBlock = {
val intent = Intent()
@@ -67,7 +64,7 @@
lazyColumn.setGestureMargin(device.displayWidth / 5)
for (i in 1..10) {
// From center we scroll 2/3 of it which is 1/3 of the screen.
- lazyColumn.drag(Point(0, lazyColumn.visibleCenter.y / 3))
+ lazyColumn.drag(Point(lazyColumn.visibleCenter.x, lazyColumn.visibleCenter.y / 3))
device.wait(Until.findObject(By.desc(COMPOSE_IDLE)), 3000)
}
}
@@ -80,9 +77,5 @@
private const val CONTENT_DESCRIPTION = "IamLazy"
private const val COMPOSE_IDLE = "COMPOSE-IDLE"
-
- @Parameterized.Parameters(name = "compilation={0}")
- @JvmStatic
- fun parameters() = createCompilationParams()
}
}