-
Notifications
You must be signed in to change notification settings - Fork 213
feat: use yielding to main thread in more places #2585
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
base: main
Are you sure you want to change the base?
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
6 files reviewed, 4 comments
packages/browser/src/extensions/replay/external/network-plugin.ts
Outdated
Show resolved
Hide resolved
|
Size Change: +13.8 kB (+0.27%) Total Size: 5.21 MB
ℹ️ View Unchanged
|
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.
Pull Request Overview
This PR introduces a new TaskQueue utility to improve page responsiveness by breaking up CPU-intensive operations and yielding to the main thread periodically. This helps reduce Interaction to Next Paint (INP) variability on pages with heavy processing.
- Adds a reusable
TaskQueueclass with time-budgeting (default 30ms) to avoid blocking the main thread - Implements helper functions
processWithYieldandprocessAsyncWithYieldfor common array processing patterns - Integrates the task queue into request queue flushing, extension initialization, performance entry processing, and session recording event handling
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/browser/src/utils/task-queue.ts | New task queue implementation with time-slicing support and helper functions for processing arrays with yielding |
| packages/browser/src/utils/tests/task-queue.test.ts | Comprehensive test suite covering task queue functionality, error handling, and yielding behavior |
| packages/browser/src/request-queue.ts | Updates flush callback to use processWithYield for processing request batches |
| packages/browser/src/posthog-core.ts | Refactors extension initialization to use TaskQueue class, removing custom time-slicing logic |
| packages/browser/src/extensions/replay/external/network-plugin.ts | Applies yielding to initial performance entry processing |
| packages/browser/src/extensions/replay/external/lazy-loaded-session-recorder.ts | Adds yielding to queued event processing |
| .changeset/smooth-wolves-mix.md | Changeset documenting the new feature |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
packages/browser/src/extensions/replay/external/network-plugin.ts
Outdated
Show resolved
Hide resolved
packages/browser/src/extensions/replay/external/lazy-loaded-session-recorder.ts
Show resolved
Hide resolved
5b464a3 to
dcd9d73
Compare
dcd9d73 to
e1fa634
Compare
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.
Pull Request Overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
packages/browser/src/extensions/replay/external/lazy-loaded-session-recorder.ts
Outdated
Show resolved
Hide resolved
e1fa634 to
6e5b1cb
Compare
6e5b1cb to
d0eb1ea
Compare
d0eb1ea to
48f90cd
Compare
48f90cd to
17209ef
Compare
packages/browser/src/posthog-core.ts
Outdated
| logger.error('Error initializing extension:', error) | ||
| }, | ||
| }) | ||
| taskQueue.enqueueAll(initTasks) |
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.
Do we not need to call a method to actually start the processing?
cb31d6a to
2cbb48f
Compare
rafaeelaudibert
left a comment
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 have a couple comments, can you confirm this is correct before merging?
packages/browser/src/posthog-core.ts
Outdated
| (error) => { | ||
| logger.error('Error initializing extension:', error) | ||
| } |
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.
Should this be on a catch to make it clearer?
2cbb48f to
dacaa49
Compare
dacaa49 to
b92c680
Compare
|
backed out the Promise changes that's too spicy for now |
b92c680 to
f80e82a
Compare
f80e82a to
6e6c4fd
Compare
6e6c4fd to
8594615
Compare
8594615 to
e8c0f0a
Compare
|
Local INP testing Results Summary
|

we tested yielding processing to the main thread periodically and it worked well
reducing variability of INP on pages using that mode
let's abstract the task queue processing approach and use it in a few more places where we might be running over large arrays and cause a long task