Skip to content

Conversation

@gnoff
Copy link
Collaborator

@gnoff gnoff commented Apr 23, 2024

Fizz and Flight both currently have a work schedule that enqueues tasks for retrying in a new macrotask. however it means that any given render will be split across multiple tasks even if any thenables that suspend are available within a microtask. This PR updates the ping mechanism for both renderers to schedule retry work on the microtask queue.

As we've run into many times in React this is another instance where being able to schedule a microtask to run at the end of the queue would be ideal since we can optimize flushing better.

Fizz and Flight both currently have a work schedule that enqueues tasks for retrying in a new macrotask. however it means that any given render will be split across multiple tasks even if any thenables that suspend are available within a microtask. This PR updates the ping mechanism for both renderers to schedule retry work on the microtask queue.

As we've run into many times in React this is another instance where being able to schedule a microtask to run at the end of the queue would be ideal since we can optimize flushing better.
@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Apr 23, 2024
@react-sizebot
Copy link

Comparing: 699d03c...e77baa2

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.js = 497.71 kB 497.71 kB = 88.93 kB 88.93 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 504.00 kB 504.00 kB = 89.95 kB 89.95 kB
facebook-www/ReactDOM-prod.classic.js = 591.14 kB 591.14 kB = 103.91 kB 103.91 kB
facebook-www/ReactDOM-prod.modern.js = 566.95 kB 566.95 kB = 100.12 kB 100.12 kB
oss-experimental/react-noop-renderer/cjs/react-noop-renderer-flight-server.production.js +3.45% 2.03 kB 2.10 kB +0.84% 0.72 kB 0.72 kB
oss-stable-semver/react-noop-renderer/cjs/react-noop-renderer-flight-server.production.js +3.45% 2.03 kB 2.10 kB +0.84% 0.72 kB 0.72 kB
oss-stable/react-noop-renderer/cjs/react-noop-renderer-flight-server.production.js +3.45% 2.03 kB 2.10 kB +0.84% 0.72 kB 0.72 kB
oss-experimental/react-noop-renderer/cjs/react-noop-renderer-flight-server.development.js +2.66% 2.41 kB 2.47 kB +0.77% 0.91 kB 0.91 kB
oss-stable-semver/react-noop-renderer/cjs/react-noop-renderer-flight-server.development.js +2.66% 2.41 kB 2.47 kB +0.77% 0.91 kB 0.91 kB
oss-stable/react-noop-renderer/cjs/react-noop-renderer-flight-server.development.js +2.66% 2.41 kB 2.47 kB +0.77% 0.91 kB 0.91 kB
test_utils/ReactAllWarnings.js Deleted 64.80 kB 0.00 kB Deleted 16.14 kB 0.00 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
oss-experimental/react-noop-renderer/cjs/react-noop-renderer-flight-server.production.js +3.45% 2.03 kB 2.10 kB +0.84% 0.72 kB 0.72 kB
oss-stable-semver/react-noop-renderer/cjs/react-noop-renderer-flight-server.production.js +3.45% 2.03 kB 2.10 kB +0.84% 0.72 kB 0.72 kB
oss-stable/react-noop-renderer/cjs/react-noop-renderer-flight-server.production.js +3.45% 2.03 kB 2.10 kB +0.84% 0.72 kB 0.72 kB
oss-experimental/react-noop-renderer/cjs/react-noop-renderer-flight-server.development.js +2.66% 2.41 kB 2.47 kB +0.77% 0.91 kB 0.91 kB
oss-stable-semver/react-noop-renderer/cjs/react-noop-renderer-flight-server.development.js +2.66% 2.41 kB 2.47 kB +0.77% 0.91 kB 0.91 kB
oss-stable/react-noop-renderer/cjs/react-noop-renderer-flight-server.development.js +2.66% 2.41 kB 2.47 kB +0.77% 0.91 kB 0.91 kB
oss-experimental/react-noop-renderer/cjs/react-noop-renderer-server.production.js +1.13% 5.68 kB 5.75 kB +0.62% 1.46 kB 1.47 kB
oss-stable-semver/react-noop-renderer/cjs/react-noop-renderer-server.production.js +1.13% 5.68 kB 5.75 kB +0.62% 1.46 kB 1.47 kB
oss-stable/react-noop-renderer/cjs/react-noop-renderer-server.production.js +1.13% 5.68 kB 5.75 kB +0.62% 1.46 kB 1.47 kB
oss-experimental/react-noop-renderer/cjs/react-noop-renderer-server.development.js +1.01% 6.31 kB 6.38 kB +0.41% 1.70 kB 1.70 kB
oss-stable-semver/react-noop-renderer/cjs/react-noop-renderer-server.development.js +1.01% 6.31 kB 6.38 kB +0.41% 1.70 kB 1.70 kB
oss-stable/react-noop-renderer/cjs/react-noop-renderer-server.development.js +1.01% 6.31 kB 6.38 kB +0.41% 1.70 kB 1.70 kB
test_utils/ReactAllWarnings.js Deleted 64.80 kB 0.00 kB Deleted 16.14 kB 0.00 kB

Generated by 🚫 dangerJS against e77baa2

Copy link

@Jesus-Rojas Jesus-Rojas left a comment

Choose a reason for hiding this comment

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

Good job !!

if (!hasLoaded) {
throw promise;
}
console.log('rendering');
Copy link

@Jesus-Rojas Jesus-Rojas Apr 23, 2024

Choose a reason for hiding this comment

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

Remove is unnecessary

Suggested change
console.log('rendering');
console.log('rendering');

resolve();
});
writable.on('error', () => {
writable.on('error', pl => {

Choose a reason for hiding this comment

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

Param not used

Suggested change
writable.on('error', pl => {
writable.on('error', () => {

Copy link
Collaborator

@sebmarkbage sebmarkbage left a comment

Choose a reason for hiding this comment

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

This is problematic because there can be many macro tasks already scheduled on the queue from the I/O threads. The goal of the macro task is to exhaust as many of those as possible to be able to render through as much as possible.

This was more efficient when we were able to synchronously render through things that had already loaded in RSC. We still can do that for instrumented promises such as those coming from a Flight stream. I.e. most Fizz work. But ideally we could also do it with more preloads and such with Flight too.

@gnoff
Copy link
Collaborator Author

gnoff commented Apr 25, 2024

closing in favor of #28907

@gnoff gnoff closed this Apr 25, 2024
@gnoff gnoff deleted the single-task-work branch July 25, 2024 22:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed React Core Team Opened by a member of the React Core Team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants