Skip to content

Commit

Permalink
Not sure what's up with these compiled lambdas crashing at runtime..
Browse files Browse the repository at this point in the history
  • Loading branch information
pyricau committed Sep 11, 2024
1 parent 4bbcaec commit 5ccd042
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 27 deletions.
20 changes: 14 additions & 6 deletions papa/src/main/java/papa/InputEventTrigger.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ class InputEventTrigger private constructor(
get() = renderedUptime != null

private val inputEventFrameRenderedCallbacks =
mutableListOf(OnFrameRenderedListener { renderedUptime = it })
mutableListOf<OnFrameRenderedListener>(object : OnFrameRenderedListener {
override fun onFrameRendered(frameRenderedUptime: Duration) {
renderedUptime = frameRenderedUptime
}
})

fun onInputEventFrameRendered(listener: OnFrameRenderedListener) {
Handlers.checkOnMainThread()
Expand All @@ -33,12 +37,16 @@ class InputEventTrigger private constructor(
deliveryUptime: Duration
): InputEventTrigger {
val trigger = InputEventTrigger(inputEvent, deliveryUptime)
inputEventWindow.postOnWindowFrameRendered {
for (callback in trigger.inputEventFrameRenderedCallbacks) {
callback.onFrameRendered(it)
// When compiling with Java11 we get AbstractMethodError at runtime when this is a lambda.
@Suppress("ObjectLiteralToLambda")
inputEventWindow.postOnWindowFrameRendered(object : OnFrameRenderedListener {
override fun onFrameRendered(frameRenderedUptime: Duration) {
for (callback in trigger.inputEventFrameRenderedCallbacks) {
callback.onFrameRendered(frameRenderedUptime)
}
trigger.inputEventFrameRenderedCallbacks.clear()
}
trigger.inputEventFrameRenderedCallbacks.clear()
}
})
return trigger
}
}
Expand Down
36 changes: 20 additions & 16 deletions papa/src/main/java/papa/InteractionRuleClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -162,22 +162,26 @@ private class InteractionEngine<ParentEventType : Any>(
stopRunning()
finishingInteractions += this
recordEvent()
Choreographers.postOnFrameRendered { frameRenderedUptime ->
trace.endTrace()
choreographer.removeFrameCallback(this)
finishingInteractions -= this
val eventsCopy = sentEvents.toList()
resultListener.onInteractionResult(
Finished(
data = InteractionResultDataPayload(
interactionTrigger = interactionTrigger,
runningFrameCount = frameCountSinceStart,
sentEvents = eventsCopy,
),
endFrameRenderedUptime = frameRenderedUptime
// When compiling with Java11 we get AbstractMethodError at runtime when this is a lambda.
@Suppress("ObjectLiteralToLambda")
Choreographers.postOnFrameRendered(object : OnFrameRenderedListener {
override fun onFrameRendered(frameRenderedUptime: Duration) {
trace.endTrace()
choreographer.removeFrameCallback(this@RealRunningInteraction)
finishingInteractions -= this@RealRunningInteraction
val eventsCopy = sentEvents.toList()
resultListener.onInteractionResult(
Finished(
data = InteractionResultDataPayload(
interactionTrigger = interactionTrigger,
runningFrameCount = frameCountSinceStart,
sentEvents = eventsCopy,
),
endFrameRenderedUptime = frameRenderedUptime
)
)
)
}
}
})
return this
}

Expand Down Expand Up @@ -272,7 +276,7 @@ interface OnEventScope<ParentEventType : Any, EventType : ParentEventType> {
return startInteraction(
trigger = trigger,
trace = trace
).finish()
).finish()
}

/**
Expand Down
16 changes: 11 additions & 5 deletions papa/src/main/java/papa/internal/Perfs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import papa.AppVisibilityState.INVISIBLE
import papa.AppVisibilityState.VISIBLE
import papa.Choreographers
import papa.Handlers
import papa.OnFrameRenderedListener
import papa.PapaEvent.AppLaunch
import papa.PapaEventListener
import papa.PreLaunchState
Expand All @@ -46,6 +47,7 @@ import papa.internal.LaunchedActivityStartingTransition.STARTED
import papa.internal.MyProcess.ErrorRetrievingMyProcessData
import papa.internal.MyProcess.MyProcessData
import papa.internal.PerfsActivityLifecycleCallbacks.Companion.trackActivityLifecycle
import kotlin.time.Duration

/**
* Singleton object centralizing state for app start and future other perf metrics.
Expand Down Expand Up @@ -418,11 +420,15 @@ internal object Perfs {
return
}
reportedFullDrawn = true
Choreographers.postOnFrameRendered { frameRenderedUptime ->
appStartData = appStartData.copy(
firstFrameAfterFullyDrawnElapsedUptimeMillis = frameRenderedUptime.inWholeMilliseconds - appStartData.processStartUptimeMillis
)
}
// When compiling with Java11 we get AbstractMethodError at runtime when this is a lambda.
@Suppress("ObjectLiteralToLambda")
Choreographers.postOnFrameRendered(object : OnFrameRenderedListener {
override fun onFrameRendered(frameRenderedUptime: Duration) {
appStartData = appStartData.copy(
firstFrameAfterFullyDrawnElapsedUptimeMillis = frameRenderedUptime.inWholeMilliseconds - appStartData.processStartUptimeMillis
)
}
})
}

fun customFirstEvent(
Expand Down

0 comments on commit 5ccd042

Please sign in to comment.