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

[scheduler] Post to MessageChannel instead of window #14234

Merged
merged 1 commit into from
Nov 14, 2018

Conversation

acdlite
Copy link
Collaborator

@acdlite acdlite commented Nov 14, 2018

Scheduler needs to schedule a task that fires after paint. To do this, it currently posts a message event to window. This happens on every frame until the queue is empty. An unfortunate consequence is that every other message event handler also gets called on every frame; even if they exit immediately, this adds up to significant per-frame overhead.

Instead, we'll create a MessageChannel and post to that, with a fallback to the old behavior if MessageChannel does not exist.

Scheduler needs to schedule a task that fires after paint. To do this,
it currently posts a message event to `window`. This happens on every
frame until the queue is empty. An unfortunate consequence is that every
other message event handler also gets called on every frame; even if
they exit immediately, this adds up to significant per-frame overhead.

Instead, we'll create a MessageChannel and post to that, with a
fallback to the old behavior if MessageChannel does not exist.
@acdlite acdlite merged commit 5bce0ef into facebook:master Nov 14, 2018
@sizebot
Copy link

sizebot commented Nov 14, 2018

React: size: 🔺+0.9%, gzip: 🔺+0.9%

Details of bundled changes.

Comparing: d7fd679...9126e21

react

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react.development.js +0.3% +0.5% 95.93 KB 96.25 KB 25.21 KB 25.32 KB UMD_DEV
react.production.min.js 🔺+0.9% 🔺+0.9% 11.54 KB 11.65 KB 4.58 KB 4.63 KB UMD_PROD
react.profiling.min.js +0.8% +0.8% 13.69 KB 13.8 KB 5.11 KB 5.15 KB UMD_PROFILING

scheduler

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
scheduler.development.js +1.5% +1.8% 21.77 KB 22.09 KB 5.88 KB 5.98 KB NODE_DEV
scheduler.production.min.js 🔺+2.1% 🔺+2.4% 4.7 KB 4.8 KB 1.84 KB 1.88 KB NODE_PROD
Scheduler-dev.js +1.5% +1.8% 22 KB 22.33 KB 5.92 KB 6.03 KB FB_WWW_DEV
Scheduler-prod.js 🔺+1.7% 🔺+2.3% 13.18 KB 13.41 KB 2.88 KB 2.94 KB FB_WWW_PROD

Generated by 🚫 dangerJS

@@ -533,13 +533,14 @@ if (typeof window !== 'undefined' && window._schedMock) {
};

// We use the postMessage trick to defer idle work until after the repaint.
var port = null;
var messageKey =
Copy link
Collaborator

Choose a reason for hiding this comment

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

The overhead of this is no longer necessary in this mechanism since it's a unique channel.

} else {
// Otherwise post a message to the window. This isn't ideal because message
// handlers will fire on every frame until the queue is empty, including
// some browser extensions.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need this fallback? IE9? Do we even support that anyway?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Idk, for some reason I thought FB did but I guess we don't any longer

@sebmarkbage
Copy link
Collaborator

Maybe just fallback to setTimeout(, 0) since that code is really small and at least makes it work while slow. That also makes test environments work maybe. nextTick polyfills seems to do that in cases they give up.

jetoneza pushed a commit to jetoneza/react that referenced this pull request Jan 23, 2019
Scheduler needs to schedule a task that fires after paint. To do this,
it currently posts a message event to `window`. This happens on every
frame until the queue is empty. An unfortunate consequence is that every
other message event handler also gets called on every frame; even if
they exit immediately, this adds up to significant per-frame overhead.

Instead, we'll create a MessageChannel and post to that, with a
fallback to the old behavior if MessageChannel does not exist.
n8schloss pushed a commit to n8schloss/react that referenced this pull request Jan 31, 2019
Scheduler needs to schedule a task that fires after paint. To do this,
it currently posts a message event to `window`. This happens on every
frame until the queue is empty. An unfortunate consequence is that every
other message event handler also gets called on every frame; even if
they exit immediately, this adds up to significant per-frame overhead.

Instead, we'll create a MessageChannel and post to that, with a
fallback to the old behavior if MessageChannel does not exist.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants