Skip to content

andr, sdk: refactor session replay to look for keyboard on single UI pass - #1008

Draft
murki wants to merge 6 commits into
mainfrom
murki/replay-refactor
Draft

murki wants to merge 6 commits into
mainfrom
murki/replay-refactor

Conversation

@murki

@murki murki commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Main changes in ReplayCaptureEngine and ReplayParser.

Before the traversal was split in two:

  1. Main thread: create the ReplayRect tree
  2. bg thread: Filter/add layers (remove ignored views, add screen/window, add keyboard)

Now it's been condensed in the single first pass. Also deleted a bunch of confusing extra classes (ReplayDecoration, ReplayFilter, FilteredCapture typealias).

Updated examples/android/MainActivity.kt to use the new List<ReplayRect> signature in the onScreenCaptured override, replacing the removed FilteredCapture typealias.

test session: https://timeline.bitdrift.dev/session/f21546b4-95de-485c-a9a1-ceb485292d99

Screenshot 2026-06-03 at 5 33 00 PM
  • CHANGELOG.md's "Unreleased" section has been updated, if applicable.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors the Android session replay capture pipeline to perform view traversal, filtering, and decoration (screen bounds + keyboard overlay) in a single main-thread pass, removing the previous two-stage parser+filter+decorations flow.

Changes:

  • Consolidates capture output into a single List<ReplayRect> produced by ReplayParser (now also adds screen bounds + keyboard overlays and drops Ignore elements).
  • Removes ReplayFilter, ReplayDecorations, and the FilteredCapture typealias; moves “identical frame” suppression into ReplayCaptureEngine.
  • Updates public/internal callback and encoder signatures from FilteredCapture to List<ReplayRect> and adjusts tests/targets accordingly.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
platform/jvm/replay/src/test/kotlin/io/bitdrift/capture/replay/ReplayFilterTest.kt Removes unit tests tied to the deleted ReplayFilter.
platform/jvm/replay/src/main/kotlin/io/bitdrift/capture/replay/ReplayPreviewClient.kt Updates callback type to List<ReplayRect>.
platform/jvm/replay/src/main/kotlin/io/bitdrift/capture/replay/IReplayLogger.kt Updates public callback signature to List<ReplayRect>.
platform/jvm/replay/src/main/kotlin/io/bitdrift/capture/replay/internal/ReplayParser.kt Single-pass traversal now emits final replay rect list (includes screen bounds + IME overlays; filters Ignore).
platform/jvm/replay/src/main/kotlin/io/bitdrift/capture/replay/internal/ReplayFilter.kt Deletes the old filter stage and FilteredCapture typealias.
platform/jvm/replay/src/main/kotlin/io/bitdrift/capture/replay/internal/ReplayEncoder.kt Updates encoder input type to List<ReplayRect>.
platform/jvm/replay/src/main/kotlin/io/bitdrift/capture/replay/internal/ReplayDecorations.kt Deletes the old decoration stage (screen + keyboard overlays).
platform/jvm/replay/src/main/kotlin/io/bitdrift/capture/replay/internal/ReplayCaptureEngine.kt Wires new parser output directly into encoding; adds “identical capture” suppression locally.
platform/jvm/gradle-test-app/src/androidTest/java/io/bitdrift/gradletestapp/TestUtils.kt Updates test logger plumbing to use List<ReplayRect>.
platform/jvm/gradle-test-app/src/androidTest/java/io/bitdrift/gradletestapp/ComposeReplayTest.kt Updates test types to use List<ReplayRect>.
platform/jvm/gradle-test-app/src/androidTest/java/io/bitdrift/gradletestapp/AndroidViewReplayTest.kt Updates test types to use List<ReplayRect>.
platform/jvm/capture/src/main/kotlin/io/bitdrift/capture/events/SessionReplayTarget.kt Updates target callback signature to List<ReplayRect>.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

}
result.add(viewMapper.mapView(currentNode))

// 3. Map view and filter out Ignored types (addressing TODO in ReplayFilter)
Comment on lines +77 to +85
private fun filter(capture: List<ReplayRect>): List<ReplayRect>? {
// This capture is identical to the previous one, filter it out
return if (capture == previousCapture) {
null
} else {
previousCapture = capture
capture
}
}
@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown

Size Comparison Report (x86_64)

Metric APK (KB) SO (KB)
Baseline 3431 1296
Current 3431 1296
Difference 0 0

APK size unchanged. SO size unchanged.

Copilot finished work on behalf of murki June 3, 2026 21:52
@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown

Android Benchmark Results

Device: PR: Emulator - Android SDK built for x86_64 (API 31) | main: Emulator - Android SDK built for x86_64 (API 31)

Note: Benchmarks run on emulator. Results may vary between runs and may differ from physical devices.

Allocations

Test PR main Δ
logHttpNetworkLog50FieldsAndHeadersAndFieldProviders 917 923 -0.7%
logNotMatched5000Fields 10 10 0.0%
logNotMatchedNoFields 1 1 0.0%
trackSpansWithFields 140 140 0.0%
trackSpansWithoutFields 55 54 +1.9%
webViewBridgeBridgeReady 60 60 0.0%
webViewBridgeCustomLog 61 63 -3.2%
webViewBridgeInvalidJson 38 38 0.0%
webViewBridgeWebVitalCLS 174 175 -0.6%

Timing

Test PR main Δ
logHttpNetworkLog50FieldsAndHeadersAndFieldProviders 268.85 us 238.13 us +12.9%
logNotMatched5000Fields 2.95 ms 2.45 ms +20.6%
logNotMatchedNoFields 474 ns 449 ns +5.7%
trackSpansWithFields 587.50 us 487.89 us +20.4%
trackSpansWithoutFields 8.34 us 7.87 us +6.0%
webViewBridgeBridgeReady 7.86 us 8.39 us -6.3%
webViewBridgeCustomLog 14.68 us 18.05 us -18.7%
webViewBridgeInvalidJson 87.45 us 82.34 us +6.2%
webViewBridgeWebVitalCLS 19.97 us 21.01 us -5.0%


private fun filter(capture: List<ReplayRect>): List<ReplayRect>? {
// This capture is identical to the previous one, filter it out
return if (capture == previousCapture) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before we were ignoring when the app is backgrounded

From main:

// This capture is identical to the previous one, or is empty, filter it out
// One interesting case when capture is empty is when the application is backgrounded.
return if (filteredCapture == previousCapture || filteredCapture.isEmpty()) {
    null
} else {
    previousCapture = filteredCapture
    filteredCapture
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah good point, this might need more testing

private val replayEncoder: ReplayEncoder = ReplayEncoder(),
private val clock: IClock = DefaultClock.getInstance(),
) {
private var previousCapture: List<ReplayRect>? = null

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is only accessed from the background thread so probably ok for now to not make it thread safe

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea


internal typealias Capture = List<List<ReplayRect>>

internal class ReplayParser(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if we should rename this now as is doing more things now than just parsing (e.g. computeDisplayRect(), compute IME overlay, etc)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair

filter(timedValue.value)?.let { filteredCapture ->
replayCaptureMetrics.parseDuration = timedValue.duration
replayCaptureMetrics.viewCountAfterFilter = filteredCapture.size
val screen = captureDecorations.addDecorations(filteredCapture)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was happening in background thread, we should measure the impact on jank for this change (I can take a look)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah in particular there will be 1 extra check for every root view to look for the keyboard, I'd expect it to be very low overhead but probably not 0

@FranAguilera

Copy link
Copy Markdown
Contributor

Will take a look this week

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants