sentry-javascript: Replay is making my Angular app super slow
Is there an existing issue for this?
- I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- I have reviewed the documentation https://docs.sentry.io/
- I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases
How do you use Sentry?
Sentry Saas (sentry.io)
Which package are you using?
SDK Version
7.31.1
Framework Version
Angular 14.2.8
Link to Sentry event
No response
SDK Setup
Sentry.init({
...environment.sentryApi,
replaysSessionSampleRate: 0.5,
replaysOnErrorSampleRate: 1.0,
integrations: [
new Sentry.Replay(),
new Sentry.Integrations.TryCatch({
XMLHttpRequest: false
}),
new BrowserTracing({
tracingOrigins: ['apiUrl']
})
],
tracesSampleRate: 0.5
});
Steps to Reproduce
Add the Replay integration to the Angular app. Without it the website is smooth, as soon as I add it it gets super slow continuously
Expected Result
Add Replay shouldn’t impact performance so much, or it’s basically becomes unusable
Actual Result
Everything is slow
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 5
- Comments: 38 (22 by maintainers)
Commits related to this issue
- fix(rrweb): Use unpatched `requestAnimationFrame` when possible As explained here: https://github.com/getsentry/sentry-javascript/issues/6946#issuecomment-1875842171 the usage of `requestAnimationFra... — committed to getsentry/rrweb by mydea 6 months ago
- fix(rrweb): Use unpatched `requestAnimationFrame` when possible (#150) As explained here: https://github.com/getsentry/sentry-javascript/issues/6946#issuecomment-1875842171 the usage of `requestAni... — committed to getsentry/rrweb by mydea 6 months ago
- feat(replay): Update rrweb to 2.7.3 (#10072) This bump contains the following changes: - fix(rrweb): Use unpatched requestAnimationFrame when possible [#150](https://github.com/getsentry/rrweb/pu... — committed to getsentry/sentry-javascript by mydea 6 months ago
- replay: remover perf warning Resolved by https://github.com/getsentry/sentry-javascript/issues/6946 — committed to getsentry/sentry-docs by bruno-garcia 6 months ago
- replay: remover perf warning (#8852) Resolved by https://github.com/getsentry/sentry-javascript/issues/6946 — committed to getsentry/sentry-docs by bruno-garcia 6 months ago
- fix(rrweb): Use unpatched `requestAnimationFrame` when possible (#150) As explained here: https://github.com/getsentry/sentry-javascript/issues/6946#issuecomment-1875842171 the usage of `requestAni... — committed to getsentry/rrweb by mydea 6 months ago
I have also been seeing this issue as I’ve been integrating Sentry into our Angular app. I’ve done some digging into it and I believe I’ve found the main cause of the performance hit (at least in our case).
It appears that rrweb is running a call to
requestAnimationFrameon a loop (in a method calledperiodicallyClear), and in AngularrequestAnimationFrameis patched so it triggers a change detection whenever it is invoked. This means change detections are happening repeatedly, which slows the app down massively.I’ve managed to restore the performance of our app by disabling the patching of
requestAnimationFrame, and I’ve shared the results below. But ideally the rrweb library should be using the non-patched version of RAF (as well as other patched methods likesetTimeout, etc) to avoid unnecessary change detection.Here’s a screenshot of a profile from our app, when it’s just sitting idly on a simple page for 4 seconds:
And here’s a profile of the exact same page sitting for 4 seconds, but with the
requestAnimationFrameNgZone patch disabled:To those following in the thread: in our newest sdk (version 7.46.0) - we will now add a breadcrumb to the replay when we detect > 1000 mutations. There are also two new experimental options:
mutationBreadcrumbLimit- changes the count of mutations before creating a new breadcrumbmutationLimit- this option will instead take a new full snapshot of the entire DOM instead of processing each individual mutation in the queue. This should improve performance for your users, though you should still look into optimize your code to reduce the amount of DOM mutations!.In order to use it you’ll have to initialize
Replaylike so:Please try it out and let us know how it works for you.
Our angular app has dynamic forms and other complex UI/DOM stuff going on as well.
However, in the past we have used other replay-like products in the past including hotjar, logrocket not to mention a few more. This is the only one that is producing serious performance penalties to our angular app to the point of us having to disable it. So there is some sort of extra inefficiency built into it whether by design or not that is producing this overhead, and until such overhead is brought down to a manageable level we will not be able to use replay going forward.
Thanks for the info! yeah, updating to a more recent version of replay should improve performance a bit. we will work on further improvements down the line too! But it will be great to unblock this angular specific issue here 🙏
I have prepared a repo with a few components, What I found is that it is really difficult to reproduce “super slow” evidence with a demo app.
https://github.com/meriturva/sentry-replay-angular-slower
Here few gifs I have recorded to show that replay makes render slower: Without replay:
With replay:

If you need access to a really slow site (when the replay is enabled) I could arrange private access to a staging site where it will be quite easy to show the difference.
Hi @jpike88, I’m sorry that you’re experiencing this performance impact. I understand that this is a serious problem for you and we’re working on improving performance. Our running theory is that the slowdown is caused by a spike in DOM mutations within a very short time period. We’ll soon be able to detect these spikes to confirm our theory. Angular’s default change detection might contribute to this spike, given that it is likely to update DOM elements that necessarily don’t need to be updated.
We’ll keep you posted on further improvements and developments in this area 😃