-
Notifications
You must be signed in to change notification settings - Fork 148
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-958] Use a performance observable instead of the lifecycle #2818
Conversation
a3ad039
to
c1df39d
Compare
Bundles Sizes Evolution
🚀 CPU Performance
🧠 Memory Performance
|
1c6601d
to
438c232
Compare
import { getDocumentTraceId } from '../tracing/getDocumentTraceId' | ||
import { FAKE_INITIAL_DOCUMENT, computeRelativePerformanceTiming } from './resourceUtils' | ||
|
||
export function retrieveInitialDocumentResourceTiming( |
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: I think we can "clean" this up and don't fake a performance entry like this. Are you planning to do it when we'll migrate the NAVIGATION
performance entry to the new createPerformanceObserver
?
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.
I thought of cleaning it but the PR is already quite substantial. Like you mention, let's discuss it in the following NAVIGATION PR ;)
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2818 +/- ##
==========================================
+ Coverage 93.31% 93.64% +0.32%
==========================================
Files 263 266 +3
Lines 7482 7548 +66
Branches 1669 1679 +10
==========================================
+ Hits 6982 7068 +86
+ Misses 500 480 -20 ☔ View full report in Codecov by Sentry. |
0378a18
to
c2e5411
Compare
const performanceResourceSubscription = createPerformanceObservable(configuration, { | ||
type: RumPerformanceEntryType.RESOURCE, | ||
buffered: true, | ||
}).subscribe((entries) => { | ||
for (const entry of entries) { | ||
if (entry.entryType === RumPerformanceEntryType.RESOURCE && !isRequestKind(entry)) { | ||
if (!isRequestKind(entry)) { |
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.
👏 So nice to have this
if (buffered) { | ||
notify(instance, bufferedEntries) | ||
} |
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.
💬 suggestion: this is Safari behavior, but I'm not sure this is the standard behavior. We should at least state this as a comment. Maybe this could be done more explicitly by passing a { synchronousBufferedEntriesCallback: true }
flag to mockPerformanceObserver
.
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.
Hum, the mock always triggers entries synchronously even for non buffered ones. To me, it's more by convenience to avoid playing with the clock each time we use mockPerformanceObserver
.
So I'm not sure it's a good idea to add a special behaviour for buffered entries and if we generalise it for any entries adding synchronousBufferedEntriesCallback: true
everywhere will be a bit cumbersome. Wdyt?
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.
Let's not talk about async/sync, but whether the PerformanceObserver callback is called during or after observe()
. My point is not to make everything asynchronous, just to make the observe
default behavior closer to the standard.
Again, I'd be fine with just documenting this with a comment so we know why it's implemented like this.
1bc1470
to
96c47cc
Compare
/to-staging |
🚂 Branch Integration: starting soon, median merge time is 0s Commit 96c47cc4f5 will soon be integrated into staging-27. Use |
Integrated commit sha: 96c47cc Co-authored-by: Aymeric Mortemousque <aymeric.mortemousque@datadoghq.com>
🚂 Branch Integration: This commit was successfully integrated Commit 96c47cc4f5 has been merged into staging-27 in merge commit ae24d645c0. |
/to-staging |
🚂 Branch Integration: starting soon, median merge time is 11m Commit 96c47cc4f5 will soon be integrated into staging-28. Use |
🚨 Branch Integration: This merge request has conflicts We couldn't automatically merge the commit 96c47cc4f5 into staging-28! You can use this resolution PR: #2849 to fix the conflicts. If you need support, contact us on Slack #devflow with those details! |
After upgrade with this change, we're seeing a new PerformanceObserver instance is created after every user click / action. |
This change should not have a performance impact. Creating a new PerformanceObserver is pretty cheap, and the memory associated to it should be negligeable compared to memory used by the rest of the SDK and/or your webapp. |
Motivation
The performanceCollection has too many concerns and limitations:
The goal of this PR is to be able to use separate performance observer for each entry type:
Changes
performanceObservable
which removes the performanceObservable fallbackretrieveInitialDocumentResourceTiming
fromperformanceCollection.ts
in/domain/resource/retrieveInitialDocumentResourceTiming.ts
performanceObservable
to collect performance resourceperformanceObservable
inwaitPageActivityEnd
Testing
I have gone over the contributing documentation.