@ -4,7 +4,6 @@
package org.mozilla.fenix.perf
package org.mozilla.fenix.perf
import android.util.Log
import android.view.View
import android.view.View
import android.view.ViewGroup
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.LinearLayout
@ -25,7 +24,6 @@ import org.mozilla.fenix.helpers.HomeActivityTestRule
private const val EXPECTED _SUPPRESSION _COUNT = 19
private const val EXPECTED _SUPPRESSION _COUNT = 19
@Suppress ( " TopLevelPropertyNaming " ) // it's silly this would have a different naming convention b/c no const
@Suppress ( " TopLevelPropertyNaming " ) // it's silly this would have a different naming convention b/c no const
private val EXPECTED _RUNBLOCKING _RANGE = 0. . 1 // CI has +1 counts compared to local runs: increment these together
private val EXPECTED _RUNBLOCKING _RANGE = 0. . 1 // CI has +1 counts compared to local runs: increment these together
private const val EXPECTED _VIEW _HIERARCHY _DEPTH = 12
private const val EXPECTED _RECYCLER _VIEW _CONSTRAINT _LAYOUT _CHILDREN = 4
private const val EXPECTED _RECYCLER _VIEW _CONSTRAINT _LAYOUT _CHILDREN = 4
private const val EXPECTED _NUMBER _OF _INFLATION = 12
private const val EXPECTED _NUMBER _OF _INFLATION = 12
@ -39,12 +37,6 @@ private val failureMsgRunBlocking = getErrorMessage(
implications = " using runBlocking may block the main thread and have other negative performance implications? "
implications = " using runBlocking may block the main thread and have other negative performance implications? "
)
)
private val failureMsgViewHierarchyDepth = getErrorMessage (
shortName = " view hierarchy depth " ,
implications = " having a deep view hierarchy can slow down measure/layout performance? "
) + " 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 (
private val failureMsgRecyclerViewConstraintLayoutChildren = getErrorMessage (
shortName = " ConstraintLayout being a common direct descendant of a RecyclerView " ,
shortName = " ConstraintLayout being a common direct descendant of a RecyclerView " ,
implications = " ConstraintLayouts are slow to inflate and are primarily used to flatten deep " +
implications = " ConstraintLayouts are slow to inflate and are primarily used to flatten deep " +
@ -89,14 +81,12 @@ class StartupExcessiveResourceUseTest {
val actualRunBlocking = RunBlockingCounter . count . get ( )
val actualRunBlocking = RunBlockingCounter . count . get ( )
val rootView = activityTestRule . activity . findViewById < LinearLayout > ( R . id . rootContainer )
val rootView = activityTestRule . activity . findViewById < LinearLayout > ( R . id . rootContainer )
val actualViewHierarchyDepth = countAndLogViewHierarchyDepth ( rootView , 1 )
val actualRecyclerViewConstraintLayoutChildren = countRecyclerViewConstraintLayoutChildren ( rootView , null )
val actualRecyclerViewConstraintLayoutChildren = countRecyclerViewConstraintLayoutChildren ( rootView , null )
val actualNumberOfInflations = InflationCounter . inflationCount . get ( )
val actualNumberOfInflations = InflationCounter . inflationCount . get ( )
assertEquals ( failureMsgStrictMode , EXPECTED _SUPPRESSION _COUNT , actualSuppresionCount )
assertEquals ( failureMsgStrictMode , EXPECTED _SUPPRESSION _COUNT , actualSuppresionCount )
assertTrue ( failureMsgRunBlocking + " actual: $actualRunBlocking " , actualRunBlocking in EXPECTED _RUNBLOCKING _RANGE )
assertTrue ( failureMsgRunBlocking + " actual: $actualRunBlocking " , actualRunBlocking in EXPECTED _RUNBLOCKING _RANGE )
assertEquals ( failureMsgViewHierarchyDepth , EXPECTED _VIEW _HIERARCHY _DEPTH , actualViewHierarchyDepth )
assertEquals (
assertEquals (
failureMsgRecyclerViewConstraintLayoutChildren ,
failureMsgRecyclerViewConstraintLayoutChildren ,
EXPECTED _RECYCLER _VIEW _CONSTRAINT _LAYOUT _CHILDREN ,
EXPECTED _RECYCLER _VIEW _CONSTRAINT _LAYOUT _CHILDREN ,
@ -106,19 +96,6 @@ class StartupExcessiveResourceUseTest {
}
}
}
}
private fun countAndLogViewHierarchyDepth ( view : View , level : Int ) : Int {
// Log for debugging purposes: not sure if this is actually helpful.
val indent = " | " . repeat ( level - 1 )
Log . d ( " Startup...Test " , " ${indent} $view " )
return if ( view !is ViewGroup ) {
level
} else {
val maxDepth = view . children . map { countAndLogViewHierarchyDepth ( it , level + 1 ) } . maxOrNull ( )
maxDepth ?: level
}
}
private fun countRecyclerViewConstraintLayoutChildren ( view : View , parent : View ? ) : Int {
private fun countRecyclerViewConstraintLayoutChildren ( view : View , parent : View ? ) : Int {
val viewValue = if ( parent is RecyclerView && view is ConstraintLayout ) {
val viewValue = if ( parent is RecyclerView && view is ConstraintLayout ) {
1
1