Commit 54c7dc70 authored by Michael Comella's avatar Michael Comella Committed by Michael Comella
Browse files

For #16376: assert num ConstraintLayout direct descend RecyclerView.

I'm not convinced this is a useful test because the performance
characteristics seem unfortunately nuanced: if the test fails, it implies
you shouldn't add more but that isn't necessarily true (for example, if
your RV child has a large depth). Furthermore, we haven't measured in a
variety of circumstances that layouts like LinearLayout perform better
as RecyclerView children so maybe it only held for the one small case we
used it in.
parent b0a1e088
......@@ -7,7 +7,9 @@ package org.mozilla.fenix.ui
import android.util.Log
import android.view.View
import android.view.ViewGroup
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.children
import androidx.recyclerview.widget.RecyclerView
import androidx.test.uiautomator.UiDevice
......@@ -24,6 +26,7 @@ private const val EXPECTED_SUPPRESSION_COUNT = 11
private const val EXPECTED_RUNBLOCKING_COUNT = 2
private const val EXPECTED_COMPONENT_INIT_COUNT = 42
private const val EXPECTED_VIEW_HIERARCHY_DEPTH = 12
private val failureMsgStrictMode = getErrorMessage(
shortName = "StrictMode suppression",
......@@ -46,6 +49,13 @@ private val failureMsgViewHierarchyDepth = getErrorMessage(
) + "Please note that we're not sure if this is a useful metric to assert: with your feedback, " +
"we'll find out over time if it is or is not."
private val failureMsgRecyclerViewConstraintLayoutChildren = getErrorMessage(
shortName = "ConstraintLayout being a common direct descendant of a RecyclerView",
implications = "ConstraintLayouts are slow to inflate and are primarily used to flatten deep " +
"view hierarchies so can be under-performant as a common RecyclerView child?"
) + "Please note that we're not sure if this is a useful metric to assert: with your feedback, " +
"we'll find out over time if it is or is not."
* A performance test to limit the number of StrictMode suppressions and number of runBlocking used
* on startup.
......@@ -79,12 +89,20 @@ class StartupExcessiveResourceUseTest {
val actualSuppresionCount = activityTestRule.activity.components.strictMode.suppressionCount.get().toInt()
val actualRunBlocking = RunBlockingCounter.count.get()
val actualComponentInitCount = ComponentInitCount.count.get()
val actualViewHierarchyDepth = countAndLogViewHierarchyDepth(activityTestRule.activity.rootContainer, 1)
val rootView = activityTestRule.activity.rootContainer
val actualViewHierarchyDepth = countAndLogViewHierarchyDepth(rootView, 1)
val actualRecyclerViewConstraintLayoutChildren = countRecyclerViewConstraintLayoutChildren(rootView, null)
assertEquals(failureMsgStrictMode, EXPECTED_SUPPRESSION_COUNT, actualSuppresionCount)
assertEquals(failureMsgRunBlocking, EXPECTED_RUNBLOCKING_COUNT, actualRunBlocking)
assertEquals(failureMsgComponentInit, EXPECTED_COMPONENT_INIT_COUNT, actualComponentInitCount)
assertEquals(failureMsgViewHierarchyDepth, EXPECTED_VIEW_HIERARCHY_DEPTH, actualViewHierarchyDepth)
......@@ -101,6 +119,20 @@ private fun countAndLogViewHierarchyDepth(view: View, level: Int): Int {
private fun countRecyclerViewConstraintLayoutChildren(view: View, parent: View?): Int {
val viewValue = if (parent is RecyclerView && view is ConstraintLayout) {
} else {
return if (view !is ViewGroup) {
} else {
viewValue + view.children.sumBy { countRecyclerViewConstraintLayoutChildren(it, view) }
private fun getErrorMessage(shortName: String, implications: String) = """$shortName count does not match expected count.
If this PR removed a $shortName call, great! Please decrease the count.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment