sentry-cocoa icon indicating copy to clipboard operation
sentry-cocoa copied to clipboard

SessionReplay causes user-visible frame drop

Open dfed opened this issue 1 year ago • 5 comments

Platform

iOS

Environment

Production, Develop, TestFlight, Other

Installed

Swift Package Manager

Version

8.26.0

Xcode Version

15.4

Did it work on previous versions?

8.25.0

Steps to Reproduce

Set the following options:

options.experimental.sessionReplay.errorSampleRate = 1.0
options.experimental.sessionReplay.sessionSampleRate = 1.0
options.experimental.sessionReplay.redactAllText = false
options.experimental.sessionReplay.redactAllImages = false

Expected Result

Do not see user-visible frame drops

Actual Result

See user visible frame drops every second

Are you willing to submit a PR?

No response

dfed avatar May 21 '24 16:05 dfed

Probably worth mentioning that the view dropping frames is a Unity view that's been embedded in our iOS app. Prior to 8.26.0 replay did not capture the Unity view.

dfed avatar May 21 '24 20:05 dfed

Thanks @dfed for reaching out. We will investigate this.

brustolin avatar May 22 '24 06:05 brustolin

More info! This issue is happening in both 8.25.1 and 8.25.2, in addition to 8.26.0. 8.25.0 does not have this issue.

dfed avatar May 24 '24 21:05 dfed

I belive I know what cause the change. I dont know whether we can go back. But I will try to find an alternative solution.

brustolin avatar May 28 '24 13:05 brustolin

related: #4235

kahest avatar Aug 07 '24 12:08 kahest

  • Related to https://github.com/getsentry/sentry-react-native/issues/4499

krystofwoldrich avatar Feb 05 '25 10:02 krystofwoldrich

Rough ideas what could be the issue here, needs further investigation:

  • DefaultViewRenderer uses drawHierarchy(in:afterScreenUpdates:) which is slower than snapshotview(afterscreenupdates:) according to documentation
  • DefaultViewRenderer creates a graphics context, draws the view hierarchy, renders to image. SentryViewPhotographer then creates a graphics context, draws the rendered image into the context, draws masking overlays, renders to an image. Maybe the render passes can be reduced.
  • Instead of UIGraphicsImageRenderer it might be faster to directly use CGContext

https://github.com/getsentry/sentry-cocoa/blob/07475f9c7b72f62c9c53e3a3e87c26915cee693e/Sources/Swift/Tools/SentryViewPhotographer.swift#L13-L21

philprime avatar Feb 05 '25 10:02 philprime

Linking what @romtsn and I tried https://github.com/getsentry/sentry-cocoa/compare/kw/test-replay-cgcontext

krystofwoldrich avatar Feb 05 '25 10:02 krystofwoldrich

@krystofwoldrich I understand your approach, most of UIKit's UIView use Core Animation's CALayer in the background, but AFAIK views (especially non-public SwiftUI helper views) can also directly render to the graphics context. That's maybe why you saw partial renders.

philprime avatar Feb 05 '25 15:02 philprime

I'm experiencing this issue on 8.45.0 (and was also seeing it on 8.44.0 - my first version of Sentry). I'm adding SentrySwiftUI as the only Sentry dependency.

Frame drop is hugely evident on scrolling views at a rate of 1/s - when taking the photo - and the problem is no longer apparent when disabling Session Replay options.

mcguile avatar Feb 24 '25 08:02 mcguile

RN User shared an example of visible frames drops when panning in maps.

https://github.com/getsentry/sentry-react-native/issues/4609

krystofwoldrich avatar Mar 03 '25 09:03 krystofwoldrich

Quick update:

I have performed an extensive benchmark and analyzed potential improvement strategies in #4940. We'll discuss how to use the learnings and my proposed changes.

philprime avatar Mar 05 '25 17:03 philprime

We released two new options with v8.47.0 (and will update the documentation shortly):

Please test the new renderer by enabling it:

options.sessionReplay.enableExperimentalViewRenderer = true

Looking forward to any feedback if this improves the performance.

philprime avatar Mar 13 '25 12:03 philprime

We released two new options with v8.47.0 (and will update the documentation shortly):

Please test the new renderer by enabling it:

options.sessionReplay.enableExperimentalViewRenderer = true Looking forward to any feedback if this improves the performance.

so how do we try this in react-native? Our react-native app's perf just dropped drastically right after we enabled session replay

harrisrobin avatar Mar 19 '25 12:03 harrisrobin

@harrisrobin the options for React Native are not yet released but you can follow along this PR: https://github.com/getsentry/sentry-react-native/pull/4660

philprime avatar Mar 19 '25 12:03 philprime

The Sentry RN SDK with the performance improvements was released yesterday.

https://github.com/getsentry/sentry-react-native/releases/tag/6.10.0

import * as Sentry from '@sentry/react-native';

Sentry.init({
  integrations: [
    Sentry.mobileReplayIntegration({
      enableExperimentalViewRenderer: true,
    }),
  ],
});

krystofwoldrich avatar Mar 26 '25 15:03 krystofwoldrich

and? i am facing this issue in this package "@sentry/react-native": "^6.10.0".

CMLCNL avatar Apr 23 '25 20:04 CMLCNL

@brustolin

CMLCNL avatar Apr 23 '25 20:04 CMLCNL

@CMLCNL did you try enabling the faster experimental view renderer that we shipped in 6.10.0? It would be valuable feedback for us if you can try it and let us know if it changes the experience for you:

Sentry.init({
  integrations: [
    Sentry.mobileReplayIntegration({
      enableExperimentalViewRenderer: true,
    }),
  ],
});

kahest avatar Apr 23 '25 20:04 kahest

Hey @kahest I just tried out enableExperimentalViewRenderer but it didn't help. I can provide a repro if you want. here is what it looks like with and without session replay for us

https://github.com/user-attachments/assets/10e46df1-6fdd-4e1d-99aa-1afaafdda8a5

https://github.com/user-attachments/assets/af3f2772-627c-43dd-b228-6e53d5de2d0e

EDIT: this only happens on physical iPhone and not on simulator

AlirezaHadjar avatar Apr 27 '25 08:04 AlirezaHadjar

Hi @AlirezaHadjar, I would highly appreciate the repro! If you do not want to post it publicly, feel free to send it to [email protected] instead.

EDIT: this only happens on physical iPhone and not on simulator

Which model of iPhone are you using?

philprime avatar Apr 28 '25 07:04 philprime

Hi @AlirezaHadjar, I would highly appreciate the repro! If you do not want to post it publicly, feel free to send it to [email protected] instead.

EDIT: this only happens on physical iPhone and not on simulator

Which model of iPhone are you using?

Cool, I'll create one today. And I'm using iPhone 16 pro max

AlirezaHadjar avatar Apr 28 '25 07:04 AlirezaHadjar

Hi @AlirezaHadjar, I would highly appreciate the repro! If you do not want to post it publicly, feel free to send it to [email protected] instead.

EDIT: this only happens on physical iPhone and not on simulator

Which model of iPhone are you using?

Cool, I'll create one today. And I'm using iPhone 16 pro max

@philprime here is the repro

AlirezaHadjar avatar Apr 29 '25 13:04 AlirezaHadjar

Thank you for the repro @AlirezaHadjar,

just to confirm that my observations match yours.

Adding the following to the Sentry init improves the stutters from periodical to occasional on my test device (iPhone 15).

  integrations: [
    Sentry.mobileReplayIntegration({
      enableExperimentalViewRenderer: true,
    }),
  ],

Video Replay (no extra flags)

https://github.com/user-attachments/assets/8a23f81c-5c67-47cf-b7aa-6dec9810306c

Video Replay (enableExperimentalViewRenderer: true)

https://github.com/user-attachments/assets/e7f669ce-f572-4d50-bedd-9026026c776b

krystofwoldrich avatar Apr 29 '25 14:04 krystofwoldrich

Hey @krystofwoldrich yes adding enableExperimentalViewRenderer will definitely improve the performance but doesn't fix it completely. in this repro I don't notice the stutter with enableExperimentalViewRenderer but in our app it still stutters but less

AlirezaHadjar avatar Apr 29 '25 16:04 AlirezaHadjar

@AlirezaHadjar thank you for the reproducible project and thank you @krystofwoldrich for checking it out.

I just created #5155 so we can have a fresh issue to investigate potential improvement strategies.

philprime avatar Apr 30 '25 09:04 philprime

I've also tried running the reproducer app with the following settings, but the output from the FastViewRendering is corrupted (example).

Sentry.mobileReplayIntegration({
  enableExperimentalViewRenderer: true,
  enableFastViewRendering: true,
}),

krystofwoldrich avatar Apr 30 '25 20:04 krystofwoldrich