Skip to content

Commit 612e105

Browse files
Add Simultaneous Worker Listener Actions
Simulates multiple workers subscribing to same event and then triggering multiple actions all queued.
1 parent 08d93be commit 612e105

File tree

5 files changed

+63
-3
lines changed

5 files changed

+63
-3
lines changed

benchmarks/performance-poetry/complex-poetry/src/androidTest/java/com/squareup/benchmarks/performance/complex/poetry/RenderPassTest.kt

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import androidx.test.platform.app.InstrumentationRegistry
88
import androidx.test.uiautomator.UiDevice
99
import com.squareup.benchmarks.performance.complex.poetry.PerformancePoetryActivity.Companion.EXTRA_PERF_CONFIG_INITIALIZING
1010
import com.squareup.benchmarks.performance.complex.poetry.PerformancePoetryActivity.Companion.EXTRA_PERF_CONFIG_REPEAT
11+
import com.squareup.benchmarks.performance.complex.poetry.PerformancePoetryActivity.Companion.EXTRA_PERF_CONFIG_SIMULTANEOUS
1112
import com.squareup.benchmarks.performance.complex.poetry.PerformancePoetryActivity.Companion.EXTRA_RUNTIME_FRAME_TIMEOUT
1213
import com.squareup.benchmarks.performance.complex.poetry.cyborgs.landscapeOrientation
1314
import com.squareup.benchmarks.performance.complex.poetry.cyborgs.openRavenAndNavigate
@@ -16,7 +17,6 @@ import com.squareup.benchmarks.performance.complex.poetry.cyborgs.waitForPoetry
1617
import com.squareup.benchmarks.performance.complex.poetry.instrumentation.RenderPassCountingInterceptor
1718
import org.junit.Assert.fail
1819
import org.junit.Before
19-
import org.junit.Ignore
2020
import org.junit.Test
2121
import org.junit.runner.RunWith
2222

@@ -30,6 +30,7 @@ class RenderPassTest {
3030
val title: String,
3131
val useInitializingState: Boolean,
3232
val useHighFrequencyRange: Boolean,
33+
val simultaneousActions: Int,
3334
val baselineExpectation: RenderExpectation,
3435
val frameTimeoutExpectation: RenderExpectation
3536
)
@@ -68,6 +69,10 @@ class RenderPassTest {
6869
runRenderPassCounter(COMPLEX_NO_INITIALIZING_HIGH_FREQUENCY, useFrameTimeout = false)
6970
}
7071

72+
@Test fun renderPassCounterBaselineComplexNoInitializingStateSimultaneous() {
73+
runRenderPassCounter(COMPLEX_NO_INITIALIZING_SIMULTANEOUS, useFrameTimeout = false)
74+
}
75+
7176
@Test fun renderPassCounterFrameTimeoutComplexWithInitializingState() {
7277
runRenderPassCounter(COMPLEX_INITIALIZING, useFrameTimeout = true)
7378
}
@@ -76,11 +81,14 @@ class RenderPassTest {
7681
runRenderPassCounter(COMPLEX_NO_INITIALIZING, useFrameTimeout = true)
7782
}
7883

79-
@Ignore("#841")
8084
@Test fun renderPassCounterFrameTimeoutComplexNoInitializingStateHighFrequencyEvents() {
8185
runRenderPassCounter(COMPLEX_NO_INITIALIZING_HIGH_FREQUENCY, useFrameTimeout = true)
8286
}
8387

88+
@Test fun renderPassCounterFrameTimeoutComplexNoInitializingStateSimultaneous() {
89+
runRenderPassCounter(COMPLEX_NO_INITIALIZING_SIMULTANEOUS, useFrameTimeout = true)
90+
}
91+
8492
private fun runRenderPassCounter(
8593
scenario: Scenario,
8694
useFrameTimeout: Boolean
@@ -92,6 +100,10 @@ class RenderPassTest {
92100
EXTRA_PERF_CONFIG_INITIALIZING,
93101
scenario.useInitializingState
94102
)
103+
putExtra(
104+
EXTRA_PERF_CONFIG_SIMULTANEOUS,
105+
scenario.simultaneousActions
106+
)
95107
if (useFrameTimeout) {
96108
putExtra(EXTRA_RUNTIME_FRAME_TIMEOUT, useFrameTimeout)
97109
}
@@ -220,6 +232,7 @@ class RenderPassTest {
220232
title = "the 'Raven navigation with initializing state scenario'",
221233
useInitializingState = true,
222234
useHighFrequencyRange = false,
235+
simultaneousActions = 0,
223236
baselineExpectation = RenderExpectation(
224237
totalPasses = 57..57,
225238
freshRenderedNodes = 85..85,
@@ -236,6 +249,7 @@ class RenderPassTest {
236249
title = "the 'Raven navigation (no initializing state) scenario'",
237250
useInitializingState = false,
238251
useHighFrequencyRange = false,
252+
simultaneousActions = 0,
239253
baselineExpectation = RenderExpectation(
240254
totalPasses = 56..56,
241255
freshRenderedNodes = 83..83,
@@ -266,18 +280,37 @@ class RenderPassTest {
266280
title = "the 'Raven navigation (no initializing state) scenario with high frequency events'",
267281
useInitializingState = false,
268282
useHighFrequencyRange = true,
283+
simultaneousActions = 0,
269284
baselineExpectation = RenderExpectation(
270285
totalPasses = 181..181,
271286
freshRenderedNodes = 213..213,
272287
staleRenderedNodes = 2350..2350
273288
),
274289
frameTimeoutExpectation = RenderExpectation(
275-
totalPasses = 88..97,
290+
totalPasses = 88..97, // On Pixel 6: 56..61
276291
freshRenderedNodes = 106..108,
277292
staleRenderedNodes = 679..698
278293
)
279294
)
280295

296+
val COMPLEX_NO_INITIALIZING_SIMULTANEOUS = Scenario(
297+
title = "the 'Raven navigation (no initializing state) scenario with simultaneous events" +
298+
" AND high frequency events'",
299+
useInitializingState = false,
300+
useHighFrequencyRange = true,
301+
simultaneousActions = 20,
302+
baselineExpectation = RenderExpectation(
303+
totalPasses = 762..762,
304+
freshRenderedNodes = 253..253,
305+
staleRenderedNodes = 38919..38919
306+
),
307+
frameTimeoutExpectation = RenderExpectation(
308+
totalPasses = 88..97, // on Pixel 6: 56..61,
309+
freshRenderedNodes = 176..180,
310+
staleRenderedNodes = 4690..4700
311+
)
312+
)
313+
281314
fun congrats(
282315
subject: String,
283316
value: String,

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class PerformancePoemWorkflow(
6363
) : PoemWorkflow, StatefulWorkflow<Poem, State, ClosePoem, OverviewDetailScreen>() {
6464

6565
sealed class State {
66+
val isLoading: Boolean = false
6667
// N.B. This state is a smell. We include it to be able to mimic smells
6768
// we encounter in real life. Best practice would be to fold it
6869
// into [Selected(NO_SELECTED_STANZA)] at the very least.
@@ -95,6 +96,16 @@ class PerformancePoemWorkflow(
9596
renderState: State,
9697
context: RenderContext
9798
): OverviewDetailScreen {
99+
if (simulatedPerfConfig.simultaneousActions > 0) {
100+
repeat(simulatedPerfConfig.simultaneousActions) { index ->
101+
context.runningWorker(
102+
worker = isLoading.asTraceableWorker("SimultaneousSubscribePoem-$index"),
103+
key = "Poem-$index"
104+
) {
105+
noAction()
106+
}
107+
}
108+
}
98109
return when (renderState) {
99110
Initializing -> {
100111
// Again, the entire `Initializing` state is a smell, which is most obvious from the

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import com.squareup.benchmarks.performance.complex.poetry.PerformancePoemsBrowse
88
import com.squareup.benchmarks.performance.complex.poetry.instrumentation.ActionHandlingTracingInterceptor
99
import com.squareup.benchmarks.performance.complex.poetry.instrumentation.SimulatedPerfConfig
1010
import com.squareup.benchmarks.performance.complex.poetry.instrumentation.TraceableWorker
11+
import com.squareup.benchmarks.performance.complex.poetry.instrumentation.asTraceableWorker
1112
import com.squareup.benchmarks.performance.complex.poetry.views.BlankScreen
1213
import com.squareup.sample.container.overviewdetail.OverviewDetailScreen
1314
import com.squareup.sample.poetry.PoemListScreen.Companion.NO_POEM_SELECTED
@@ -18,6 +19,7 @@ import com.squareup.sample.poetry.PoemsBrowserWorkflow
1819
import com.squareup.sample.poetry.model.Poem
1920
import com.squareup.workflow1.Snapshot
2021
import com.squareup.workflow1.StatefulWorkflow
22+
import com.squareup.workflow1.WorkflowAction.Companion.noAction
2123
import com.squareup.workflow1.action
2224
import com.squareup.workflow1.runningWorker
2325
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
@@ -76,6 +78,16 @@ class PerformancePoemsBrowserWorkflow(
7678
renderState: State,
7779
context: RenderContext
7880
): OverviewDetailScreen {
81+
if (simulatedPerfConfig.simultaneousActions > 0) {
82+
repeat(simulatedPerfConfig.simultaneousActions) { index ->
83+
context.runningWorker(
84+
worker = isLoading.asTraceableWorker("SimultaneousSubscribeBrowser-$index"),
85+
key = "Browser-$index"
86+
) {
87+
noAction()
88+
}
89+
}
90+
}
7991
val poemListProps = Props(
8092
poems = renderProps,
8193
eventHandlerTag = ActionHandlingTracingInterceptor::keyForTrace

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class PerformancePoetryActivity : AppCompatActivity() {
6666
complexityDelay = intent.getLongExtra(EXTRA_PERF_CONFIG_DELAY, 200L),
6767
useInitializingState = intent.getBooleanExtra(EXTRA_PERF_CONFIG_INITIALIZING, false),
6868
repeatOnNext = intent.getIntExtra(EXTRA_PERF_CONFIG_REPEAT, 0),
69+
simultaneousActions = intent.getIntExtra(EXTRA_PERF_CONFIG_SIMULTANEOUS, 0),
6970
traceFrameLatency = intent.getBooleanExtra(EXTRA_PERF_CONFIG_FRAME_LATENCY, false),
7071
traceEventLatency = intent.getBooleanExtra(EXTRA_PERF_CONFIG_ACTION_TRACING, false),
7172
traceRenderingPasses = intent.getBooleanExtra(EXTRA_PERF_CONFIG_RENDERING, false)
@@ -241,6 +242,7 @@ class PerformancePoetryActivity : AppCompatActivity() {
241242
const val EXTRA_PERF_CONFIG_RENDERING = "complex.poetry.performance.config.track.rendering"
242243
const val EXTRA_PERF_CONFIG_REPEAT = "complex.poetry.performance.config.repeat.amount"
243244
const val EXTRA_PERF_CONFIG_DELAY = "complex.poetry.performance.config.delay.length"
245+
const val EXTRA_PERF_CONFIG_SIMULTANEOUS = "complex.poetry.performance.config.simultaneous"
244246
const val EXTRA_RUNTIME_FRAME_TIMEOUT =
245247
"complex.poetry.performance.config.runtime.frametimeout"
246248

benchmarks/performance-poetry/complex-poetry/src/main/java/com/squareup/benchmarks/performance/complex/poetry/instrumentation/SimulatedPerfConfig.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ data class SimulatedPerfConfig(
1717
val complexityDelay: Long,
1818
val useInitializingState: Boolean,
1919
val repeatOnNext: Int = 0,
20+
val simultaneousActions: Int = 0,
2021
val traceRenderingPasses: Boolean = false,
2122
val traceFrameLatency: Boolean = false,
2223
val traceEventLatency: Boolean = false
@@ -27,6 +28,7 @@ data class SimulatedPerfConfig(
2728
complexityDelay = 0,
2829
useInitializingState = false,
2930
repeatOnNext = 0,
31+
simultaneousActions = 0,
3032
traceRenderingPasses = false,
3133
traceFrameLatency = false,
3234
traceEventLatency = false

0 commit comments

Comments
 (0)