Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Simultaneous Worker Listener Actions #861

Merged
merged 1 commit into from
Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
import com.squareup.benchmarks.performance.complex.poetry.PerformancePoetryActivity.Companion.EXTRA_PERF_CONFIG_INITIALIZING
import com.squareup.benchmarks.performance.complex.poetry.PerformancePoetryActivity.Companion.EXTRA_PERF_CONFIG_REPEAT
import com.squareup.benchmarks.performance.complex.poetry.PerformancePoetryActivity.Companion.EXTRA_PERF_CONFIG_SIMULTANEOUS
import com.squareup.benchmarks.performance.complex.poetry.PerformancePoetryActivity.Companion.EXTRA_RUNTIME_FRAME_TIMEOUT
import com.squareup.benchmarks.performance.complex.poetry.cyborgs.landscapeOrientation
import com.squareup.benchmarks.performance.complex.poetry.cyborgs.openRavenAndNavigate
Expand All @@ -16,7 +17,6 @@ import com.squareup.benchmarks.performance.complex.poetry.cyborgs.waitForPoetry
import com.squareup.benchmarks.performance.complex.poetry.instrumentation.RenderPassCountingInterceptor
import org.junit.Assert.fail
import org.junit.Before
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith

Expand All @@ -30,6 +30,7 @@ class RenderPassTest {
val title: String,
val useInitializingState: Boolean,
val useHighFrequencyRange: Boolean,
val simultaneousActions: Int,
val baselineExpectation: RenderExpectation,
val frameTimeoutExpectation: RenderExpectation
)
Expand Down Expand Up @@ -68,6 +69,10 @@ class RenderPassTest {
runRenderPassCounter(COMPLEX_NO_INITIALIZING_HIGH_FREQUENCY, useFrameTimeout = false)
}

@Test fun renderPassCounterBaselineComplexNoInitializingStateSimultaneous() {
runRenderPassCounter(COMPLEX_NO_INITIALIZING_SIMULTANEOUS, useFrameTimeout = false)
}

@Test fun renderPassCounterFrameTimeoutComplexWithInitializingState() {
runRenderPassCounter(COMPLEX_INITIALIZING, useFrameTimeout = true)
}
Expand All @@ -76,11 +81,14 @@ class RenderPassTest {
runRenderPassCounter(COMPLEX_NO_INITIALIZING, useFrameTimeout = true)
}

@Ignore("#841")
@Test fun renderPassCounterFrameTimeoutComplexNoInitializingStateHighFrequencyEvents() {
runRenderPassCounter(COMPLEX_NO_INITIALIZING_HIGH_FREQUENCY, useFrameTimeout = true)
}

@Test fun renderPassCounterFrameTimeoutComplexNoInitializingStateSimultaneous() {
runRenderPassCounter(COMPLEX_NO_INITIALIZING_SIMULTANEOUS, useFrameTimeout = true)
}

private fun runRenderPassCounter(
scenario: Scenario,
useFrameTimeout: Boolean
Expand All @@ -92,6 +100,10 @@ class RenderPassTest {
EXTRA_PERF_CONFIG_INITIALIZING,
scenario.useInitializingState
)
putExtra(
EXTRA_PERF_CONFIG_SIMULTANEOUS,
scenario.simultaneousActions
)
if (useFrameTimeout) {
putExtra(EXTRA_RUNTIME_FRAME_TIMEOUT, useFrameTimeout)
}
Expand Down Expand Up @@ -220,6 +232,7 @@ class RenderPassTest {
title = "the 'Raven navigation with initializing state scenario'",
useInitializingState = true,
useHighFrequencyRange = false,
simultaneousActions = 0,
baselineExpectation = RenderExpectation(
totalPasses = 57..57,
freshRenderedNodes = 85..85,
Expand All @@ -236,6 +249,7 @@ class RenderPassTest {
title = "the 'Raven navigation (no initializing state) scenario'",
useInitializingState = false,
useHighFrequencyRange = false,
simultaneousActions = 0,
baselineExpectation = RenderExpectation(
totalPasses = 56..56,
freshRenderedNodes = 83..83,
Expand Down Expand Up @@ -266,18 +280,37 @@ class RenderPassTest {
title = "the 'Raven navigation (no initializing state) scenario with high frequency events'",
useInitializingState = false,
useHighFrequencyRange = true,
simultaneousActions = 0,
baselineExpectation = RenderExpectation(
totalPasses = 181..181,
freshRenderedNodes = 213..213,
staleRenderedNodes = 2350..2350
),
frameTimeoutExpectation = RenderExpectation(
totalPasses = 88..97,
totalPasses = 88..97, // On Pixel 6: 56..61
freshRenderedNodes = 106..108,
staleRenderedNodes = 679..698
)
)

val COMPLEX_NO_INITIALIZING_SIMULTANEOUS = Scenario(
title = "the 'Raven navigation (no initializing state) scenario with simultaneous events" +
" AND high frequency events'",
useInitializingState = false,
useHighFrequencyRange = true,
simultaneousActions = 20,
baselineExpectation = RenderExpectation(
totalPasses = 762..762,
freshRenderedNodes = 253..253,
staleRenderedNodes = 38919..38919
),
frameTimeoutExpectation = RenderExpectation(
totalPasses = 88..97, // on Pixel 6: 56..61,
freshRenderedNodes = 176..180,
staleRenderedNodes = 4690..4700
)
)

fun congrats(
subject: String,
value: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class PerformancePoemWorkflow(
) : PoemWorkflow, StatefulWorkflow<Poem, State, ClosePoem, OverviewDetailScreen>() {

sealed class State {
val isLoading: Boolean = false
// N.B. This state is a smell. We include it to be able to mimic smells
// we encounter in real life. Best practice would be to fold it
// into [Selected(NO_SELECTED_STANZA)] at the very least.
Expand Down Expand Up @@ -95,6 +96,16 @@ class PerformancePoemWorkflow(
renderState: State,
context: RenderContext
): OverviewDetailScreen {
if (simulatedPerfConfig.simultaneousActions > 0) {
repeat(simulatedPerfConfig.simultaneousActions) { index ->
context.runningWorker(
worker = isLoading.asTraceableWorker("SimultaneousSubscribePoem-$index"),
key = "Poem-$index"
) {
noAction()
}
}
}
return when (renderState) {
Initializing -> {
// Again, the entire `Initializing` state is a smell, which is most obvious from the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.squareup.benchmarks.performance.complex.poetry.PerformancePoemsBrowse
import com.squareup.benchmarks.performance.complex.poetry.instrumentation.ActionHandlingTracingInterceptor
import com.squareup.benchmarks.performance.complex.poetry.instrumentation.SimulatedPerfConfig
import com.squareup.benchmarks.performance.complex.poetry.instrumentation.TraceableWorker
import com.squareup.benchmarks.performance.complex.poetry.instrumentation.asTraceableWorker
import com.squareup.benchmarks.performance.complex.poetry.views.BlankScreen
import com.squareup.sample.container.overviewdetail.OverviewDetailScreen
import com.squareup.sample.poetry.PoemListScreen.Companion.NO_POEM_SELECTED
Expand All @@ -18,6 +19,7 @@ import com.squareup.sample.poetry.PoemsBrowserWorkflow
import com.squareup.sample.poetry.model.Poem
import com.squareup.workflow1.Snapshot
import com.squareup.workflow1.StatefulWorkflow
import com.squareup.workflow1.WorkflowAction.Companion.noAction
import com.squareup.workflow1.action
import com.squareup.workflow1.runningWorker
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
Expand Down Expand Up @@ -76,6 +78,16 @@ class PerformancePoemsBrowserWorkflow(
renderState: State,
context: RenderContext
): OverviewDetailScreen {
if (simulatedPerfConfig.simultaneousActions > 0) {
repeat(simulatedPerfConfig.simultaneousActions) { index ->
context.runningWorker(
worker = isLoading.asTraceableWorker("SimultaneousSubscribeBrowser-$index"),
key = "Browser-$index"
) {
noAction()
}
}
}
val poemListProps = Props(
poems = renderProps,
eventHandlerTag = ActionHandlingTracingInterceptor::keyForTrace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class PerformancePoetryActivity : AppCompatActivity() {
complexityDelay = intent.getLongExtra(EXTRA_PERF_CONFIG_DELAY, 200L),
useInitializingState = intent.getBooleanExtra(EXTRA_PERF_CONFIG_INITIALIZING, false),
repeatOnNext = intent.getIntExtra(EXTRA_PERF_CONFIG_REPEAT, 0),
simultaneousActions = intent.getIntExtra(EXTRA_PERF_CONFIG_SIMULTANEOUS, 0),
traceFrameLatency = intent.getBooleanExtra(EXTRA_PERF_CONFIG_FRAME_LATENCY, false),
traceEventLatency = intent.getBooleanExtra(EXTRA_PERF_CONFIG_ACTION_TRACING, false),
traceRenderingPasses = intent.getBooleanExtra(EXTRA_PERF_CONFIG_RENDERING, false)
Expand Down Expand Up @@ -241,6 +242,7 @@ class PerformancePoetryActivity : AppCompatActivity() {
const val EXTRA_PERF_CONFIG_RENDERING = "complex.poetry.performance.config.track.rendering"
const val EXTRA_PERF_CONFIG_REPEAT = "complex.poetry.performance.config.repeat.amount"
const val EXTRA_PERF_CONFIG_DELAY = "complex.poetry.performance.config.delay.length"
const val EXTRA_PERF_CONFIG_SIMULTANEOUS = "complex.poetry.performance.config.simultaneous"
const val EXTRA_RUNTIME_FRAME_TIMEOUT =
"complex.poetry.performance.config.runtime.frametimeout"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ data class SimulatedPerfConfig(
val complexityDelay: Long,
val useInitializingState: Boolean,
val repeatOnNext: Int = 0,
val simultaneousActions: Int = 0,
val traceRenderingPasses: Boolean = false,
val traceFrameLatency: Boolean = false,
val traceEventLatency: Boolean = false
Expand All @@ -27,6 +28,7 @@ data class SimulatedPerfConfig(
complexityDelay = 0,
useInitializingState = false,
repeatOnNext = 0,
simultaneousActions = 0,
traceRenderingPasses = false,
traceFrameLatency = false,
traceEventLatency = false
Expand Down