Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 [RUMF-1449] workaround for Firefox memory leak when using Zone.js #1860

Merged
merged 4 commits into from
Dec 9, 2022

Conversation

BenoitZugmeyer
Copy link
Member

@BenoitZugmeyer BenoitZugmeyer commented Dec 7, 2022

Motivation

Firefox is leaking memory when using Zone.js + visualViewport.addEventListener: https://bugzilla.mozilla.org/show_bug.cgi?id=1804409

Changes

  • Some light refactoring
  • Use the same strategy as for MutationObserver: we try to use the original addEventListener method instead of the patched one

Testing

  • Local
  • Staging
  • Unit
  • End to end

I have gone over the contributing documentation.

@codecov-commenter
Copy link

codecov-commenter commented Dec 7, 2022

Codecov Report

Merging #1860 (25b3365) into main (e4f2bad) will increase coverage by 0.03%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #1860      +/-   ##
==========================================
+ Coverage   93.16%   93.19%   +0.03%     
==========================================
  Files         134      137       +3     
  Lines        5135     5161      +26     
  Branches     1148     1150       +2     
==========================================
+ Hits         4784     4810      +26     
  Misses        351      351              
Impacted Files Coverage Δ
packages/core/src/browser/pageExitObservable.ts 100.00% <ø> (ø)
...ackages/core/src/domain/report/reportObservable.ts 95.00% <ø> (ø)
packages/core/src/tools/utils.ts 81.81% <ø> (-0.86%) ⬇️
...umEventsCollection/view/trackInitialViewTimings.ts 100.00% <ø> (ø)
packages/core/src/browser/addEventListener.ts 100.00% <100.00%> (ø)
packages/core/src/domain/session/sessionManager.ts 100.00% <100.00%> (ø)
packages/core/src/tools/getZoneJsOriginalValue.ts 100.00% <100.00%> (ø)
packages/core/test/stubZoneJs.ts 100.00% <100.00%> (ø)
...ages/rum-core/src/browser/domMutationObservable.ts 95.00% <100.00%> (-0.24%) ⬇️
...omain/rumEventsCollection/view/trackFirstHidden.ts 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@BenoitZugmeyer BenoitZugmeyer force-pushed the benoit/zonejs-memoryleak-workaround branch from aa0bf66 to 37efd06 Compare December 7, 2022 18:05
@BenoitZugmeyer BenoitZugmeyer marked this pull request as ready for review December 7, 2022 18:08
@BenoitZugmeyer BenoitZugmeyer requested a review from a team as a code owner December 7, 2022 18:08
@BenoitZugmeyer BenoitZugmeyer force-pushed the benoit/zonejs-memoryleak-workaround branch 2 times, most recently from 67dc751 to 751c525 Compare December 8, 2022 15:20
@BenoitZugmeyer BenoitZugmeyer force-pushed the benoit/zonejs-memoryleak-workaround branch from 751c525 to 02b4a7b Compare December 8, 2022 15:23
@BenoitZugmeyer BenoitZugmeyer force-pushed the benoit/zonejs-memoryleak-workaround branch from 02b4a7b to 669b1ec Compare December 8, 2022 15:32
const browserWindow = window as BrowserWindowWithZoneJs
let original: Target[Name] | undefined
if (browserWindow.Zone) {
original = (target as any)[browserWindow.Zone.__symbol__(name)]
Copy link
Contributor

Choose a reason for hiding this comment

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

❓ question: ‏Are we sure it works for all version of Angular/zone.js?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes this is something we used before:

const zoneSymbol = browserWindow.Zone.__symbol__
and it works with all tested Zone.js versions (from old ones used by Angularjs 1 to latest ones)

@@ -9,39 +10,6 @@ export const ONE_YEAR = 365 * ONE_DAY
export const ONE_KIBI_BYTE = 1024
export const ONE_MEBI_BYTE = 1024 * ONE_KIBI_BYTE

export const enum DOM_EVENT {
Copy link
Contributor

Choose a reason for hiding this comment

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

👏 praise: ‏I totally agree on moving it to /browser 👍

packages/core/test/specHelper.ts Outdated Show resolved Hide resolved
@BenoitZugmeyer BenoitZugmeyer merged commit af2e6a8 into main Dec 9, 2022
@BenoitZugmeyer BenoitZugmeyer deleted the benoit/zonejs-memoryleak-workaround branch December 9, 2022 13:42
liywjl pushed a commit that referenced this pull request Dec 13, 2022
…1860)

* ♻️ [RUMF-1449] rename EventEmitter to EventTarget

Use the native name rather than introducing our own concept.

* 🚚 [RUMF-1449] move addEventListener functions to a dedicated module

* 🐛 [RUMF-1449] implement a workaround for Firefox memory leak

* 👌🚚 move stubZoneJs in its own module
liywjl added a commit that referenced this pull request Dec 13, 2022
* 🐛 [RUMF-1337] Fix incorrect fetch duration

♻️ remove unused imports

♻️ remove responseDurationInfo

♻️ remove unused import

* 🔥 remove `resolveDuration`

* 🔥 remove `resolveDuration`

* 🐛 [RUMF-1449]  workaround for Firefox memory leak when using Zone.js (#1860)

* ♻️ [RUMF-1449] rename EventEmitter to EventTarget

Use the native name rather than introducing our own concept.

* 🚚 [RUMF-1449] move addEventListener functions to a dedicated module

* 🐛 [RUMF-1449] implement a workaround for Firefox memory leak

* 👌🚚 move stubZoneJs in its own module

* 👷 Bump staging to staging-51

* 🔊 Collect computed and perf entry durations (#1861)

* 🔊 Collect computed and perf entry durations

* ✨Allow internal analytics subdomain (#1863)

* 🔥 remove `resolveDuration`

🔥 remove `resolveDuration`

Co-authored-by: Benoît <[email protected]>
Co-authored-by: ci.browser-sdk <[email protected]>
Co-authored-by: Aymeric <[email protected]>
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.

5 participants