[go: nahoru, domu]

Add a pager of lazy grids benchmark

PagerOfLazyGridBenchmark_scroll[compilation=None]
frameDurationCpuMs   P50   5.1,   P90  29.7,   P95  51.5,   P99  60.5
frameOverrunMs   P50   9.9,   P90  47.8,   P95  53.1,   P99  64.6
Traces: Iteration 0 1 2 3 4 5 6 7 8 9
PagerOfLazyGridBenchmark_scroll[compilation=WarmupProfile(iterations=3)]
frameDurationCpuMs   P50   6.5,   P90  20.5,   P95  39.1,   P99  41.7
frameOverrunMs   P50   3.3,   P90  30.0,   P95  32.7,   P99  35.3
Traces: Iteration 0 1 2 3 4 5 6 7 8 9
Timed out waiting for process (androidx.compose.integration.macrobenchmark.test) to appear on google-pixel_6_pro-17011FDEE00001.
PagerOfLazyGridBenchmark_scroll[compilation=BaselineProfile]
frameDurationCpuMs   P50   6.1,   P90  21.8,   P95  45.3,   P99  49.5
frameOverrunMs   P50   5.3,   P90  36.7,   P95  39.0,   P99  47.3
Traces: Iteration 0 1 2 3 4 5 6 7 8 9
PagerOfLazyGridBenchmark_scroll[compilation=Full]
frameDurationCpuMs   P50   7.6,   P90  21.8,   P95  40.3,   P99  43.7
frameOverrunMs   P50   3.9,   P90  31.6,   P95  35.3,   P99  39.6
Traces: Iteration 0 1 2 3 4 5 6 7 8 9
PagerBenchmark_compose[compilation=Full]
frameDurationCpuMs   P50   6.5,   P90  11.3,   P95  13.6,   P99  20.7
frameOverrunMs   P50  -5.6,   P90  -2.9,   P95   2.5,   P99   7.7
Traces: Iteration 0 1 2 3 4 5 6 7 8 9

Bug: n/a
Test: PagerOfLazyGridBenchmark
Change-Id: I8ccb4c103c03594e21ac159116e5e1785e38c268
diff --git a/compose/integration-tests/macrobenchmark-target/src/main/AndroidManifest.xml b/compose/integration-tests/macrobenchmark-target/src/main/AndroidManifest.xml
index a905398..33d4ce0 100644
--- a/compose/integration-tests/macrobenchmark-target/src/main/AndroidManifest.xml
+++ b/compose/integration-tests/macrobenchmark-target/src/main/AndroidManifest.xml
@@ -228,7 +228,8 @@
                 <category android:name="android.intent.category.DEFAULT" />
             </intent-filter>
         </activity>
-        <activity
+        
+	<activity
             android:name=".VectorsListActivity"
             android:label="Compose vectors list"
             android:exported="true">
@@ -252,6 +253,14 @@
             </intent-filter>
             <intent-filter>
                 <action android:name="androidx.compose.integration.macrobenchmark.target.CROSSFADE_ACTIVITY" />
+            </intent-filter>
+	</activity>
+
+	<activity android:name=".PagerOfLazyGridActivity"
+            android:exported="true"
+            android:theme="@style/Theme.AppCompat">
+            <intent-filter>
+                <action android:name="androidx.compose.integration.macrobenchmark.target.PAGER_LAZYGRID_ACTIVITY" />
                 <category android:name="android.intent.category.DEFAULT" />
             </intent-filter>
         </activity>
diff --git a/compose/integration-tests/macrobenchmark-target/src/main/java/androidx/compose/integration/macrobenchmark/target/PagerOfLazyGridActivity.kt b/compose/integration-tests/macrobenchmark-target/src/main/java/androidx/compose/integration/macrobenchmark/target/PagerOfLazyGridActivity.kt
new file mode 100644
index 0000000..a18a1be
--- /dev/null
+++ b/compose/integration-tests/macrobenchmark-target/src/main/java/androidx/compose/integration/macrobenchmark/target/PagerOfLazyGridActivity.kt
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package androidx.compose.integration.macrobenchmark.target
+
+import android.os.Bundle
+import androidx.activity.ComponentActivity
+import androidx.activity.compose.setContent
+import androidx.compose.foundation.ExperimentalFoundationApi
+import androidx.compose.foundation.background
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.lazy.grid.GridCells
+import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
+import androidx.compose.foundation.pager.HorizontalPager
+import androidx.compose.foundation.pager.PagerState
+import androidx.compose.foundation.pager.rememberPagerState
+import androidx.compose.material.Button
+import androidx.compose.material.MaterialTheme
+import androidx.compose.material.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.remember
+import androidx.compose.runtime.rememberCoroutineScope
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.semantics.contentDescription
+import androidx.compose.ui.semantics.semantics
+import kotlinx.coroutines.launch
+
+class PagerOfLazyGridActivity : ComponentActivity() {
+    override fun onCreate(savedInstanceState: Bundle?) {
+        super.onCreate(savedInstanceState)
+
+        val pageCount = intent.getIntExtra(PageCount, 100)
+        val gridItemCount = intent.getIntExtra(GridItemCount, 100)
+
+        setContent {
+            MaterialTheme {
+                HorizontalPagerOfLazyGrid(pageCount, gridItemCount)
+            }
+        }
+
+        launchIdlenessTracking()
+    }
+
+    companion object {
+        const val PageCount = "PAGE_COUNT"
+        const val GridItemCount = "GRID_ITEM_COUNT"
+    }
+}
+
+@OptIn(ExperimentalFoundationApi::class)
+@Composable
+private fun HorizontalPagerOfLazyGrid(pages: Int = 100, gridItems: Int = 100) {
+    val pagerState: PagerState = rememberPagerState(initialPage = 1) { pages }
+    val coroutineScope = rememberCoroutineScope()
+
+    Column(
+        modifier = Modifier
+            .fillMaxSize()
+            .background(MaterialTheme.colors.background)
+    ) {
+        Button(>
+            coroutineScope.launch {
+                pagerState.animateScrollToPage(pagerState.currentPage + 1)
+            }
+        }) {
+            Text("Next")
+        }
+
+        HorizontalPager(
+            state = pagerState,
+            modifier = Modifier.semantics { contentDescription = "Pager" }
+        ) { page: Int ->
+            Grid(gridItems, page)
+        }
+    }
+}
+
+@Composable
+private fun Grid(itemCount: Int, pageNum: Int) {
+    val text = remember(pageNum) { "Hello + $pageNum" }
+    LazyVerticalGrid(
+        modifier = Modifier.fillMaxSize(),
+        columns = GridCells.Fixed(3),
+    ) {
+        items(itemCount, contentType = { "cell" }) { _ ->
+            Button( {
+                Text(text = text)
+            }
+        }
+    }
+}
diff --git a/compose/integration-tests/macrobenchmark/src/main/java/androidx/compose/integration/macrobenchmark/PagerOfLazyGridBenchmark.kt b/compose/integration-tests/macrobenchmark/src/main/java/androidx/compose/integration/macrobenchmark/PagerOfLazyGridBenchmark.kt
new file mode 100644
index 0000000..91a4b14
--- /dev/null
+++ b/compose/integration-tests/macrobenchmark/src/main/java/androidx/compose/integration/macrobenchmark/PagerOfLazyGridBenchmark.kt
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package androidx.compose.integration.macrobenchmark
+
+import android.content.Intent
+import androidx.benchmark.macro.CompilationMode
+import androidx.benchmark.macro.FrameTimingMetric
+import androidx.benchmark.macro.StartupMode
+import androidx.benchmark.macro.junit4.MacrobenchmarkRule
+import androidx.test.filters.LargeTest
+import androidx.test.platform.app.InstrumentationRegistry
+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 PagerOfLazyGridBenchmark(
+    private val compilationMode: CompilationMode
+) {
+    @get:Rule
+    val benchmarkRule = MacrobenchmarkRule()
+
+    private lateinit var device: UiDevice
+
+    @Before
+    fun setUp() {
+        val instrumentation = InstrumentationRegistry.getInstrumentation()
+        device = UiDevice.getInstance(instrumentation)
+    }
+
+    @Test
+    fun scroll() {
+        benchmarkRule.measureRepeated(
+            packageName = PackageName,
+            metrics = listOf(FrameTimingMetric()),
+            compilationMode = compilationMode,
+            startupMode = StartupMode.WARM,
+            iterations = 10,
+            setupBlock = {
+                val intent = Intent()
+                intent.action = Action
+                startActivityAndWait(intent)
+            }
+        ) {
+            val nextButton = device.findObject(By.text(NextDescription))
+            repeat(3) {
+                nextButton.click()
+                device.wait(Until.findObject(By.desc(ComposeIdle)), 3000)
+            }
+        }
+    }
+
+    companion object {
+        private const val PackageName = "androidx.compose.integration.macrobenchmark.target"
+        private const val Action =
+            "androidx.compose.integration.macrobenchmark.target.PAGER_LAZYGRID_ACTIVITY"
+        private const val ComposeIdle = "COMPOSE-IDLE"
+        private const val NextDescription = "Next"
+
+        @Parameterized.Parameters(name = "compilation={0}")
+        @JvmStatic
+        fun parameters() = createCompilationParams()
+    }
+}