Skip to content

Commit b8a816e

Browse files
Merge pull request #792 from square/sedwards/touch-to-action
Refine Latency Benchmark
2 parents c6a202a + 0d7afd2 commit b8a816e

File tree

25 files changed

+606
-322
lines changed

25 files changed

+606
-322
lines changed

benchmarks/performance-poetry/complex-benchmark/src/main/java/com/squareup/benchmarks/performance/complex/poetry/benchmark/ComplexPoetryBenchmarks.kt

Lines changed: 61 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,10 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
1414
import androidx.test.platform.app.InstrumentationRegistry
1515
import androidx.test.uiautomator.UiDevice
1616
import com.squareup.benchmarks.performance.complex.poetry.PerformancePoetryActivity
17-
import com.squareup.benchmarks.performance.complex.poetry.PerformancePoetryActivity.Companion
1817
import com.squareup.benchmarks.performance.complex.poetry.instrumentation.PerformanceTracingInterceptor
1918
import com.squareup.benchmarks.performance.complex.poetry.instrumentation.PerformanceTracingInterceptor.Companion.NODES_TO_TRACE
20-
import com.squareup.benchmarks.performance.complex.poetry.instrumentation.SimulatedPerfConfig
21-
import com.squareup.benchmarks.performance.complex.poetry.robots.landscapeOrientation
22-
import com.squareup.benchmarks.performance.complex.poetry.robots.openRavenAndNavigate
19+
import com.squareup.benchmarks.performance.complex.poetry.cyborgs.landscapeOrientation
20+
import com.squareup.benchmarks.performance.complex.poetry.cyborgs.openRavenAndNavigate
2321
import org.junit.Before
2422
import org.junit.Rule
2523
import org.junit.Test
@@ -115,15 +113,11 @@ class ComplexPoetryBenchmarks {
115113
device.landscapeOrientation()
116114
}
117115
) {
118-
startActivityAndWait{
119-
val renderPassConfig = SimulatedPerfConfig(
120-
isComplex = true,
121-
complexityDelay = 200L,
122-
useInitializingState = true,
123-
traceRenderingPasses = true,
124-
traceLatency = false
125-
)
126-
it.putExtra(PerformancePoetryActivity.PERF_CONFIG_EXTRA, renderPassConfig)
116+
startActivityAndWait { intent ->
117+
intent.apply {
118+
putExtra(PerformancePoetryActivity.EXTRA_PERF_CONFIG_INITIALIZING, true)
119+
putExtra(PerformancePoetryActivity.EXTRA_PERF_CONFIG_RENDERING, true)
120+
}
127121
}
128122
device.landscapeOrientation()
129123

@@ -139,21 +133,35 @@ class ComplexPoetryBenchmarks {
139133
}
140134

141135
/**
142-
* This test is focused on two different measurements:
136+
* This test is focused on measuring the latency of Workflow's 'work'. By that we mean how much
137+
* time Workflow spends producing the next set of updates to the View's that can be passed
138+
* to Android to draw as a frame.
143139
*
144-
* Frame-Latency-N: is the trace between passing the Rendering to the view layer and the
145-
* 'post frame rendered callback' for the Nth frame in the scenario. In other words, this traces
146-
* the time it takes from a Rendering produced by Workflow to process through the Workflow UI
147-
* layer and then be rendered in the next frame.
140+
* How do we measure this? The [EventHandlingTracingInterceptor] is a [WorkflowInterceptor] that
141+
* sets up a [RenderContextInterceptor] which has a hook for everytime we 'send' an action to the
142+
* [RenderContext]. Because this is done on the main thread, we can wrap this function call in a
143+
* synchronous trace section as it will be equivalent to the main thread 'message' that handles
144+
* all of the work before invoking the Choreographer to draw the updated Views.
148145
*
149-
* XScreen-onY-Z: is the time between the execution of event handler 'onY' and the production of
150-
* the next root Rendering by Workflow for the Zth instance of the 'onY' handler on X Screen.
151-
* In other words, this measures the time Workflow takes in processing a UI event into a new
152-
* Rendering. This will be similar to the render pass traced above, but more comprehensive to
153-
* include all of the event handling time.
146+
* We do this for certain [Worker]s results by annotating the [Worker] with a pattern in
147+
* its [toString()] - see [TraceableWorker].
148+
* We do this for UI events by adding in an injected name to the eventHandler.
149+
*
150+
* These are formatted as:
151+
* - "Worker-<Work>-Finished-XX"
152+
* - "E-<Screen>-<Event>-XX"
153+
*
154+
* Where XX is the counted instance of that event's response.
154155
*/
155156
@OptIn(ExperimentalMetricApi::class)
156157
fun benchmarkLatencyTraceSections(compilationMode: CompilationMode) {
158+
fun addLatency(intent: Intent) {
159+
intent.apply {
160+
putExtra(PerformancePoetryActivity.EXTRA_PERF_CONFIG_INITIALIZING, true)
161+
putExtra(PerformancePoetryActivity.EXTRA_PERF_CONFIG_EVENT_LATENCY, true)
162+
}
163+
}
164+
157165
benchmarkRule.measureRepeated(
158166
packageName = PACKAGE_NAME,
159167
metrics = LATENCY_TRACE_SECTIONS.map { TraceSectionMetric(it) },
@@ -165,68 +173,46 @@ class ComplexPoetryBenchmarks {
165173
device.landscapeOrientation()
166174
}
167175
) {
168-
startActivityAndWait{
169-
val renderPassConfig = SimulatedPerfConfig(
170-
isComplex = true,
171-
complexityDelay = 200L,
172-
useInitializingState = true,
173-
traceRenderingPasses = false,
174-
traceLatency = true
175-
)
176-
it.putExtra(PerformancePoetryActivity.PERF_CONFIG_EXTRA, renderPassConfig)
177-
}
176+
startActivityAndWait(::addLatency)
178177
device.landscapeOrientation()
178+
device.waitForIdle()
179179

180180
device.openRavenAndNavigate()
181181
}
182182
}
183183

184184
companion object {
185-
const val RENDER_PASSES = 61
185+
const val RENDER_PASSES = 58
186186
const val PACKAGE_NAME = "com.squareup.benchmarks.performance.complex.poetry"
187187

188188
val LATENCY_TRACE_SECTIONS = listOf(
189-
"PoemListScreen-onPoemSelected(2)-1 ",
190-
"StanzaListScreen-onStanzaSelected(4)-1 ",
191-
"StanzaScreen-onGoForth-1 ",
192-
"StanzaScreen-onGoForth-2 ",
193-
"StanzaScreen-onGoForth-3 ",
194-
"StanzaScreen-onGoForth-4 ",
195-
"StanzaScreen-onGoForth-5 ",
196-
"StanzaScreen-onGoBack-1 ",
197-
"StanzaScreen-onGoBack-2 ",
198-
"StanzaScreen-onGoBack-3 ",
199-
"StanzaScreen-onGoBack-4 ",
200-
"StanzaScreen-onGoBack-5 ",
201-
"StanzaListScreen-onExit-1 ",
202-
"Frame-Latency-00 ",
203-
"Frame-Latency-01 ",
204-
"Frame-Latency-02 ",
205-
"Frame-Latency-03 ",
206-
"Frame-Latency-04 ",
207-
"Frame-Latency-05 ",
208-
"Frame-Latency-06 ",
209-
"Frame-Latency-07 ",
210-
"Frame-Latency-08 ",
211-
"Frame-Latency-09 ",
212-
"Frame-Latency-10 ",
213-
"Frame-Latency-11 ",
214-
"Frame-Latency-12 ",
215-
"Frame-Latency-13 ",
216-
"Frame-Latency-14 ",
217-
"Frame-Latency-15 ",
218-
"Frame-Latency-16 ",
219-
"Frame-Latency-17 ",
220-
"Frame-Latency-18 ",
221-
"Frame-Latency-19 ",
222-
"Frame-Latency-20 ",
223-
"Frame-Latency-21 ",
224-
"Frame-Latency-22 ",
225-
"Frame-Latency-23 ",
226-
"Frame-Latency-24 ",
227-
"Frame-Latency-25 ",
228-
"Frame-Latency-26 ",
229-
"Frame-Latency-27 ",
189+
"E-PoemList-PoemSelected-00",
190+
"Worker-ComplexCallBrowser(2)-Finished-00",
191+
"Worker-PoemLoading-Finished-00",
192+
"E-StanzaList-StanzaSelected-00",
193+
"Worker-PoemLoading-Finished-01",
194+
"E-StanzaWorkflow-ShowNextStanza-00",
195+
"Worker-PoemLoading-Finished-02",
196+
"E-StanzaWorkflow-ShowNextStanza-01",
197+
"Worker-PoemLoading-Finished-03",
198+
"E-StanzaWorkflow-ShowNextStanza-02",
199+
"Worker-PoemLoading-Finished-04",
200+
"E-StanzaWorkflow-ShowNextStanza-03",
201+
"Worker-PoemLoading-Finished-05",
202+
"E-StanzaWorkflow-ShowNextStanza-04",
203+
"Worker-PoemLoading-Finished-06",
204+
"E-StanzaWorkflow-ShowPreviousStanza-00",
205+
"Worker-PoemLoading-Finished-07",
206+
"E-StanzaWorkflow-ShowPreviousStanza-01",
207+
"Worker-PoemLoading-Finished-08",
208+
"E-StanzaWorkflow-ShowPreviousStanza-02",
209+
"Worker-PoemLoading-Finished-09",
210+
"E-StanzaWorkflow-ShowPreviousStanza-03",
211+
"Worker-PoemLoading-Finished-10",
212+
"E-StanzaWorkflow-ShowPreviousStanza-04",
213+
"Worker-PoemLoading-Finished-11",
214+
"E-StanzaList-Exit-00",
215+
"Worker-ComplexCallBrowser(-1)-Finished-00",
230216
)
231217
}
232218
}

benchmarks/performance-poetry/complex-benchmark/src/main/java/com/squareup/benchmarks/performance/complex/poetry/benchmark/ComplexPoetryGatherBaseline.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import androidx.test.core.app.ApplicationProvider
77
import androidx.test.platform.app.InstrumentationRegistry
88
import androidx.test.uiautomator.UiDevice
99
import com.squareup.benchmarks.performance.complex.poetry.benchmark.ComplexPoetryBenchmarks.Companion.PACKAGE_NAME
10-
import com.squareup.benchmarks.performance.complex.poetry.robots.openRavenAndNavigate
10+
import com.squareup.benchmarks.performance.complex.poetry.cyborgs.openRavenAndNavigate
1111
import org.junit.Before
1212
import org.junit.Rule
1313
import org.junit.Test

0 commit comments

Comments
 (0)