Skip to content

Session replay stalls fast scrolls in React Native: main-thread render(in:) in the motion band #955

Open

Description

@benthomasmtl

Version

3.88.2 (through @posthog/react-native-plugin 2.12.6 and posthog-react-native 4.81.2)

Steps to Reproduce

  1. A React Native 0.86 app on the New Architecture (Fabric), Expo SDK 57, with session replay on and sampled at 100%. Replay config from JS: maskAllTextInputs: true, maskAllImages: false, default throttleDelayMs (1000). The RN plugin forces screenshotMode = true.
  2. Open a long scrolling screen built from ordinary RN views (cards with shadows, gradients, text).
  3. Fling the scroll view fast, several times in a row.

Expected Result

Scrolling stays as smooth as it is with replay off, which is how it behaved on posthog-ios 3.58.1 (through posthog-react-native-session-replay 1.6.0).

Actual Result

After moving from posthog-ios 3.58.1 to 3.88.2, which was the only native dependency change in that app release, fast flings stutter and the deceleration sometimes stops dead, as if the screen had been tapped. It happens about once per throttle interval while a fling is moving. Slow scrolling is fine.

The code path we traced in 3.88.2:

  • scheduleSettledCapture samples mask geometry twice, 25 ms apart. During a fling, settleVerdict returns .motion, either because the displacement is over driftBudgetPoints (50 pt) or because the two samples can't be paired when rows mount or unmount mid-scroll.
  • .motion passes preferFidelityRenderer: false, so performScreenshotCapture → collectScreenshotMetadata → UIView.toImage runs (layer.presentation() ?? layer).render(in:) over the whole window at native screen scale, on the main thread. That is a CPU render of the entire layer tree, shadows included, in the middle of the scroll's deceleration.
  • Since 3.69.9, maskAllTextInputs: true makes every RCTParagraphComponentView a mask region. On an RN screen almost every fast scroll therefore lands in .motion, and collectMaskedRegions walks the view hierarchy twice per capture.

#786 (3.70.1) added the motion band and notes that it has a real cost. The band fires on exactly the gesture where a main-thread stall is most visible.

What we measured: in Sentry, our iOS slow-frame rate on navigation transactions went from about 4.8% on the previous release (posthog-ios 3.58.1) to about 6.9% on this one. The sample is small and navigation spans don't cover scrolling, so treat it as a weak signal. We haven't profiled the stall in Instruments.

From React Native on iOS, the only levers are throttleDelayMs, sampleRate or turning replay off. screenshotModeBackgroundCapture is experimental and slated for removal in 4.0 (#937).

Suggested fix: when the settle check returns .motion, skip or defer the capture until the geometry settles instead of rendering with render(in:) on the main thread. That would match the Android side, where mid-scroll capture jank was raised in PostHog/posthog-android#750 and PostHog/posthog-js#4734. A frame taken once the scroll settles is still accurate, and a frame skipped mid-fling costs the replay very little. Failing that, letting the RN plugin turn the motion fallback off would also work.

Activity

  1. turnipdabeets commented on Oct 20, 2026

    @turnipdabeets
    Contributor

    Thanks for the detailed trace @benthomasmtl. Heads up that this is being workied on in #911 and we'll need to wire it through the React Native plugin too, @ioannisj.

  2. turnipdabeets commented on Nov 15, 2026

    @turnipdabeets
    Contributor

    @ioannisj, same question as #1035: GPU capture skips the render(in:) path while the screen is moving. Do you expect it to fix the fling stalls? React Native opt-in comes with posthog-ios 4.0 and plugin 3.0 (PostHog/posthog-js#5734).

  3. posthog commented on Nov 15, 2026

    @posthog
    Contributor

    PostHog self-driving picked up this issue. Status: Research is done.

    Somebody may already be working on it, so ask before you start a fix.

    Report (team access only): https://us.posthog.com/project/2/inbox/reports/01a1ae52-9d6f-73a7-9a6a-0b30704e23b1?link_source=github_comment

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions