-
Notifications
You must be signed in to change notification settings - Fork 140
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
🐛 [RUM-4436] fix detached node memory leak on CLS #2749
Conversation
Bundles Sizes Evolution
🚀 CPU Performance
|
381ad9e
to
6d48530
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2749 +/- ##
==========================================
+ Coverage 93.27% 93.28% +0.01%
==========================================
Files 241 241
Lines 7034 7032 -2
Branches 1554 1555 +1
==========================================
- Hits 6561 6560 -1
+ Misses 473 472 -1 ☔ View full report in Codecov by Sentry. |
76814f1
to
959c5c3
Compare
packages/rum-core/src/domain/view/viewMetrics/trackCumulativeLayoutShift.ts
Outdated
Show resolved
Hide resolved
packages/rum-core/src/domain/view/viewMetrics/trackCumulativeLayoutShift.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thought: maybe a simpler solution could be to avoid storing the target altogether.
In trackCumulativeLayoutShift
, we could have something like this:
const isLargestLayoutShift = window.update(entry)
// ... then:
if (isLargestLayoutShift) {
const clsTarget = find(
entry.sources,
(s): s is { node: HTMLElement } => !!s.node && isElementNode(s.node)
)?.node;
if (
clsTarget &&
// Check if the CLS target have been removed from the DOM between the time we collect the target reference and when we compute the selector
clsTarget.isConnected
) {
clsTargetSelector = getSelectorFromElement(clsTarget, configuration.actionNameAttribute)
}
}
}
and remove largestLayoutShiftTarget
from the window target. Also we could do the same for largestLayoutShiftTime
.
b401fa6
to
43a9ad0
Compare
Edit: As discussed during our 1:1, the |
a944ec5
to
eff59c8
Compare
…indow after 5 seconds
packages/rum-core/src/domain/view/viewMetrics/trackCumulativeLayoutShift.ts
Outdated
Show resolved
Hide resolved
packages/rum-core/src/domain/view/viewMetrics/trackCumulativeLayoutShift.spec.ts
Outdated
Show resolved
Hide resolved
packages/rum-core/src/domain/view/viewMetrics/trackCumulativeLayoutShift.spec.ts
Outdated
Show resolved
Hide resolved
/to-staging |
🚂 Branch Integration: starting soon, merge in < 9m Commit 4ebadc8b01 will soon be integrated into staging-20. This build is going to start soon! (estimated merge in less than 9m) Use |
Co-authored-by: Thomas Lebeau <[email protected]>
🚂 Branch Integration: This commit was successfully integrated Commit 4ebadc8b01 has been merged into staging-20 in merge commit 173bf4e0d7. Check out the triggered pipeline on Gitlab 🦊 |
🔨 warning: With this implementation we are computing the CSS selector lot more often:
|
packages/rum-core/src/domain/view/viewMetrics/trackCumulativeLayoutShift.ts
Outdated
Show resolved
Hide resolved
7b89929
to
8aacc27
Compare
8aacc27
to
a2e2ae1
Compare
Motivation
trackCumulativeLayoutShift keep track of the LCP target Element using a sliding window of layout shift events but this window is cleared 5 minutes after the view ends.
Within these 5 minutes, many new view events might be started meaning an increase in memory consumption du to the reference to the LCP target Element kept and preventing garbage collection of these elements (and potentially large amount of descendent)
Changes
Hold onto the LCP target element using a weak reference (
WeakRef
) to not prevent it to be garbage-collected.Testing
I have gone over the contributing documentation.