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

⚡️ Process buffered performance entries in an idle callback #1337

Merged

Conversation

amortemousque
Copy link
Contributor

Motivation

Process buffered resources in an idle callback could prevent the SDK from blocking the main thread on page load too much.

Changes

Update performance collection

Testing

  • Local
  • Staging
  • Unit
  • End to end

I have gone over the contributing documentation.

@amortemousque amortemousque requested a review from a team as a code owner February 14, 2022 11:03
@amortemousque amortemousque force-pushed the aymeric/process-buffered-resources-in-an—idle-callback branch 2 times, most recently from a06cd4e to 47a3d77 Compare February 15, 2022 10:16
@amortemousque amortemousque requested a review from a team as a code owner February 15, 2022 10:16
@amortemousque amortemousque force-pushed the aymeric/process-buffered-resources-in-an—idle-callback branch from 47a3d77 to c6335ab Compare February 15, 2022 10:31
@amortemousque amortemousque force-pushed the aymeric/process-buffered-resources-in-an—idle-callback branch from c6335ab to 2d3bb9a Compare February 15, 2022 11:20
packages/rum-core/src/browser/performanceCollection.ts Outdated Show resolved Hide resolved
callback()
}
requestIdleCallback(callOnce)
lifeCycle.subscribe(LifeCycleEventType.BEFORE_UNLOAD, callOnce)
Copy link
Contributor

Choose a reason for hiding this comment

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

❓ question: ‏what is the reasoning for calling it on unload?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know the detail behind the idle period detection but, FMU we can have cases where they are no idle periods before the unload. This is why the requestIdleCallback API provides a timeout option.

Btw the documentation states: "A timeout option is strongly recommended for required work, as otherwise it's possible multiple seconds will elapse before the callback is fired." but in our case BEFORE_UNLOAD seems more appropriate.

Copy link
Contributor

@bcaudan bcaudan Feb 15, 2022

Choose a reason for hiding this comment

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

IMO, these kind of behaviors should be explained in the code and tested.
I am wondering if this processing is not likely to be aborted by the unload anyway 🤔.

On the other hand, if we are worried about the requestIdleCallback not being called due to too much activity, let's just use a setTimeout, it should at least split this processing from the init.

wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Other concern about the async call:
#1337 (comment)

@amortemousque amortemousque force-pushed the aymeric/process-buffered-resources-in-an—idle-callback branch 2 times, most recently from 2a52d2f to b513656 Compare February 16, 2022 15:12
@@ -564,3 +564,23 @@ export function combine(...sources: any[]): unknown {
}

export type TimeoutId = ReturnType<typeof setTimeout>

export function requestIdleCallback(callback: () => void, opts?: { timeout?: number }) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we could still let this function here as it could be valuable at some point in other packages but let me know.

@amortemousque amortemousque force-pushed the aymeric/process-buffered-resources-in-an—idle-callback branch from b513656 to 238c980 Compare February 16, 2022 15:20
@amortemousque amortemousque force-pushed the aymeric/process-buffered-resources-in-an—idle-callback branch from 238c980 to d94be5a Compare February 16, 2022 15:22
@codecov-commenter
Copy link

Codecov Report

Merging #1337 (b9464c0) into main (bf16a68) will decrease coverage by 0.02%.
The diff coverage is 60.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1337      +/-   ##
==========================================
- Coverage   91.07%   91.05%   -0.03%     
==========================================
  Files         104      104              
  Lines        4268     4269       +1     
  Branches      950      950              
==========================================
  Hits         3887     3887              
- Misses        381      382       +1     
Impacted Files Coverage Δ
...ages/rum-core/src/browser/performanceCollection.ts 14.00% <0.00%> (-0.15%) ⬇️
packages/core/src/tools/utils.ts 87.33% <71.42%> (-0.51%) ⬇️
packages/rum/src/domain/record/mutationBatch.ts 100.00% <100.00%> (+9.09%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bf16a68...b9464c0. Read the comment docs.

@amortemousque amortemousque merged commit 5b3dd06 into main Feb 28, 2022
@amortemousque amortemousque deleted the aymeric/process-buffered-resources-in-an—idle-callback branch February 28, 2022 15:16
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.

4 participants