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] Always yield to native macro tasks when a virtual task completes #31787

Merged
merged 1 commit into from
Dec 17, 2024

Conversation

sebmarkbage
Copy link
Collaborator

As an alternative to #31784.

We should really just always yield each virtual task to a native task. So that it's 1:1 with native tasks. This affects when microtasks within each task happens. This brings us closer to native postTask semantics which makes it more seamless to just use that when available.

This still doesn't yield when a task expires to protect against starvation.

Copy link

vercel bot commented Dec 15, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-compiler-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 17, 2024 9:31pm

@react-sizebot
Copy link

react-sizebot commented Dec 15, 2024

Comparing: 34ee391...0310c9b

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 = 6.68 kB 6.68 kB = 1.83 kB 1.83 kB
oss-stable/react-dom/cjs/react-dom-client.production.js = 510.66 kB 510.66 kB = 91.30 kB 91.30 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 6.69 kB 6.69 kB +0.05% 1.83 kB 1.83 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js = 515.44 kB 515.44 kB = 92.15 kB 92.15 kB
facebook-www/ReactDOM-prod.classic.js = 592.36 kB 592.36 kB = 104.36 kB 104.36 kB
facebook-www/ReactDOM-prod.modern.js = 582.63 kB 582.63 kB = 102.81 kB 102.81 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
oss-experimental/scheduler/cjs/scheduler.native.production.js = 11.04 kB 10.96 kB = 2.48 kB 2.46 kB
oss-experimental/scheduler/cjs/scheduler.production.js = 10.44 kB 10.31 kB = 2.57 kB 2.52 kB
oss-experimental/scheduler/cjs/scheduler.native.development.js = 12.51 kB 12.32 kB = 2.58 kB 2.54 kB
oss-experimental/scheduler/cjs/scheduler.development.js = 12.43 kB 12.23 kB = 2.74 kB 2.69 kB
facebook-react-native/scheduler/cjs/Scheduler-dev.js = 12.39 kB 12.20 kB = 2.72 kB 2.67 kB

Generated by 🚫 dangerJS against 411e96c

@@ -241,6 +244,12 @@ function workLoop(initialTime: number) {
pop(taskQueue);
}
currentTask = peek(taskQueue);
if (enableAlwaysYieldScheduler) {
if (currentTask === null || currentTask.expirationTime > currentTime) {
// This currentTask hasn't expired we yield to the browser task.
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can't really rely on this once we switch to postTask. React already doesn't rely on this because of batching + Suspense, we have our own expiration times that switch to using the microtask queue once the time has elapsed.

So this is really just for anything at Meta that relies on the starvation protection. Maybe once this lands, that could be its own flag, too, and then Meta can try rolling it out to see what happens.

@sebmarkbage sebmarkbage merged commit f5077bc into facebook:main Dec 17, 2024
187 checks passed
github-actions bot pushed a commit that referenced this pull request Dec 17, 2024
…mpletes (#31787)

As an alternative to #31784.

We should really just always yield each virtual task to a native task.
So that it's 1:1 with native tasks. This affects when microtasks within
each task happens. This brings us closer to native `postTask` semantics
which makes it more seamless to just use that when available.

This still doesn't yield when a task expires to protect against
starvation.

DiffTrain build for [f5077bc](f5077bc)
jackpope added a commit that referenced this pull request Dec 19, 2024
#31787 introduces an experimental scheduler flag:
`enableAlwaysYieldScheduler`, which is turned off for www. There wasn't
a SchedulerFeatureFlags fork for native-fb, so the experimental change
was enabled in the Scheduler-dev build there which causes test failures
and is blocking the sync.

#31805 introduces another scheduler flag `enableRequestPaint`, which is
set as a `__VARIANT__` on www. I've set this to `true` here to preserve
the existing behavior. We can follow up with dynamic flags for native-fb
after unblocking the sync.
github-actions bot pushed a commit that referenced this pull request Dec 19, 2024
#31787 introduces an experimental scheduler flag:
`enableAlwaysYieldScheduler`, which is turned off for www. There wasn't
a SchedulerFeatureFlags fork for native-fb, so the experimental change
was enabled in the Scheduler-dev build there which causes test failures
and is blocking the sync.

#31805 introduces another scheduler flag `enableRequestPaint`, which is
set as a `__VARIANT__` on www. I've set this to `true` here to preserve
the existing behavior. We can follow up with dynamic flags for native-fb
after unblocking the sync.

DiffTrain build for [bd76ce5](bd76ce5)
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.

4 participants