GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Move guarded callback closer to usage by gaearon · Pull Request #21658 · react/react

Conversation

@gaearon

@gaearon gaearon commented Jun 10, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator

Based on #21657.

Changes:

  • 161be62?w=1: Pulls out all the code outside of (flags & Snapshot) !== NoFlags check out of the inner function. Leaves the inner function in guarded callback. The beforeActiveInstanceBlur stuff might need guarding in theory (though I'm not sure we're consistent about it now), so I wrapped it separately just to be safe.
  • d1e7f28?w=1: Prod change: don't run the inner function if flags are NoFlags. I read fiber.flags but should be ok because it's read inside right after anyway. All code inside only runs on non-zero flags so this should be safe.
  • 626cd53: Though I added this safeguard in the first commit, I decided to remove it. The only thing that host method does is dispatch an event. So it's not expected to throw. We also already don't guard it in another place. So if it used to throw, we would've likely known. Let's just not bother and keep the code simple.

Why: so that we spend less time in DEV in these guarded callbacks that don't do anything. In particular, if Fiber has no effects.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
gaearon added 4 commits June 10, 2021 20:15
@gaearon
Wrap eventhandle-specific logic in a flag
45ba73b
@gaearon
Make guarded callback more local for before mutation phase
161be62
@gaearon
Make guarded callback more local for mutation phase
d1e7f28
@gaearon
Sync forks
696c161
@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Jun 10, 2021
@gaearon
gaearon requested review from acdlite and bvaughn June 10, 2021 19:32
@sizebot

sizebot commented Jun 10, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Comparing: c153679...626cd53

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.min.js = 127.29 kB 126.91 kB = 40.81 kB 40.69 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js = 130.11 kB 129.72 kB = 41.75 kB 41.61 kB
facebook-www/ReactDOM-prod.classic.js = 406.00 kB 405.97 kB = 75.07 kB 75.05 kB
facebook-www/ReactDOM-prod.modern.js = 394.35 kB 394.32 kB = 73.25 kB 73.23 kB
facebook-www/ReactDOMForked-prod.classic.js = 406.00 kB 405.97 kB = 75.07 kB 75.05 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable-semver/react-dom/umd/react-dom.development.js = 1,004.73 kB 1,002.72 kB = 218.09 kB 217.55 kB
oss-stable/react-dom/umd/react-dom.development.js = 1,004.73 kB 1,002.72 kB = 218.09 kB 217.55 kB
oss-stable-semver/react-dom/cjs/react-dom.development.js = 956.67 kB 954.74 kB = 215.40 kB 214.90 kB
oss-stable/react-dom/cjs/react-dom.development.js = 956.67 kB 954.74 kB = 215.40 kB 214.90 kB
oss-experimental/react-art/umd/react-art.development.js = 764.34 kB 762.33 kB = 161.40 kB 160.86 kB
react-native/implementations/ReactNativeRenderer-dev.fb.js = 733.33 kB 731.36 kB = 158.20 kB 157.70 kB
oss-stable-semver/react-art/umd/react-art.development.js = 740.52 kB 738.51 kB = 156.66 kB 156.12 kB
oss-stable/react-art/umd/react-art.development.js = 740.52 kB 738.51 kB = 156.66 kB 156.12 kB
react-native/implementations/ReactNativeRenderer-dev.js = 720.11 kB 718.13 kB = 155.98 kB 155.47 kB
react-native/implementations/ReactFabric-dev.fb.js = 715.57 kB 713.61 kB = 153.82 kB 153.17 kB
react-native/implementations/ReactFabric-dev.js = 702.32 kB 700.35 kB = 151.64 kB 150.99 kB
oss-experimental/react-dom/cjs/react-dom.profiling.min.js = 137.44 kB 137.05 kB = 43.94 kB 43.82 kB
oss-experimental/react-dom/umd/react-dom.profiling.min.js = 137.35 kB 136.96 kB = 44.56 kB 44.43 kB
oss-stable-semver/react-dom/cjs/react-dom.profiling.min.js = 132.81 kB 132.42 kB = 42.39 kB 42.26 kB
oss-stable/react-dom/cjs/react-dom.profiling.min.js = 132.81 kB 132.42 kB = 42.39 kB 42.26 kB
oss-stable-semver/react-dom/umd/react-dom.profiling.min.js = 132.76 kB 132.37 kB = 43.05 kB 42.92 kB
oss-stable/react-dom/umd/react-dom.profiling.min.js = 132.76 kB 132.37 kB = 43.05 kB 42.92 kB
oss-experimental/react-reconciler/cjs/react-reconciler.development.js = 720.35 kB 718.26 kB = 153.02 kB 152.48 kB
oss-experimental/react-art/cjs/react-art.development.js = 660.81 kB 658.88 kB = 143.08 kB 142.55 kB
oss-experimental/react-dom/umd/react-dom.production.min.js = 130.07 kB 129.68 kB = 42.39 kB 42.26 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js = 130.11 kB 129.72 kB = 41.75 kB 41.61 kB
oss-stable-semver/react-reconciler/cjs/react-reconciler.development.js = 697.70 kB 695.60 kB = 148.33 kB 147.77 kB
oss-stable/react-reconciler/cjs/react-reconciler.development.js = 697.70 kB 695.60 kB = 148.33 kB 147.77 kB
oss-stable-semver/react-art/cjs/react-art.development.js = 638.35 kB 636.42 kB = 138.34 kB 137.80 kB
oss-stable/react-art/cjs/react-art.development.js = 638.35 kB 636.42 kB = 138.34 kB 137.80 kB
oss-stable-semver/react-dom/umd/react-dom.production.min.js = 127.28 kB 126.89 kB = 41.43 kB 41.33 kB
oss-stable/react-dom/umd/react-dom.production.min.js = 127.28 kB 126.89 kB = 41.43 kB 41.33 kB
oss-stable-semver/react-dom/cjs/react-dom.production.min.js = 127.29 kB 126.91 kB = 40.81 kB 40.69 kB
oss-stable/react-dom/cjs/react-dom.production.min.js = 127.29 kB 126.91 kB = 40.81 kB 40.69 kB
oss-experimental/react-test-renderer/umd/react-test-renderer.development.js = 657.36 kB 655.35 kB = 138.85 kB 138.32 kB
oss-experimental/react-test-renderer/cjs/react-test-renderer.development.js = 626.66 kB 624.73 kB = 137.35 kB 136.81 kB
facebook-www/ReactTestRenderer-dev.modern.js = 635.14 kB 633.16 kB = 136.44 kB 135.94 kB
facebook-www/ReactTestRenderer-dev.classic.js = 635.12 kB 633.15 kB = 136.43 kB 135.93 kB
oss-stable-semver/react-test-renderer/umd/react-test-renderer.development.js = 640.59 kB 638.57 kB = 135.42 kB 134.87 kB
oss-stable/react-test-renderer/umd/react-test-renderer.development.js = 640.59 kB 638.57 kB = 135.42 kB 134.87 kB
oss-stable-semver/react-test-renderer/cjs/react-test-renderer.development.js = 610.73 kB 608.81 kB = 133.92 kB 133.40 kB
oss-stable/react-test-renderer/cjs/react-test-renderer.development.js = 610.73 kB 608.81 kB = 133.92 kB 133.40 kB
facebook-react-native/react-test-renderer/cjs/ReactTestRenderer-dev.js = 622.47 kB 620.49 kB = 135.04 kB 134.53 kB
oss-experimental/react-art/umd/react-art.production.min.js = 118.80 kB 118.41 kB = 36.99 kB 36.82 kB
oss-stable-semver/react-art/umd/react-art.production.min.js = 116.41 kB 116.02 kB = 36.10 kB 35.99 kB
oss-stable/react-art/umd/react-art.production.min.js = 116.41 kB 116.02 kB = 36.10 kB 35.99 kB
react-native/implementations/ReactNativeRenderer-profiling.fb.js = 296.88 kB 295.53 kB = 52.96 kB 52.70 kB
react-native/implementations/ReactNativeRenderer-profiling.js = 296.85 kB 295.50 kB = 52.98 kB 52.72 kB
oss-experimental/react-art/cjs/react-art.production.min.js = 82.92 kB 82.53 kB = 25.83 kB 25.69 kB
react-native/implementations/ReactFabric-profiling.fb.js = 290.45 kB 289.10 kB = 51.74 kB 51.45 kB
react-native/implementations/ReactFabric-profiling.js = 290.42 kB 289.06 kB = 51.75 kB 51.45 kB
oss-experimental/react-test-renderer/cjs/react-test-renderer.production.min.js = 82.05 kB 81.66 kB = 25.56 kB 25.44 kB
oss-experimental/react-test-renderer/umd/react-test-renderer.production.min.js = 82.21 kB 81.81 kB = 25.96 kB 25.83 kB
oss-stable-semver/react-art/cjs/react-art.production.min.js = 80.53 kB 80.15 kB = 25.09 kB 24.92 kB
oss-stable/react-art/cjs/react-art.production.min.js = 80.53 kB 80.15 kB = 25.09 kB 24.92 kB
oss-stable-semver/react-test-renderer/cjs/react-test-renderer.production.min.js = 79.67 kB 79.29 kB = 24.81 kB 24.67 kB
oss-stable/react-test-renderer/cjs/react-test-renderer.production.min.js = 79.67 kB 79.29 kB = 24.81 kB 24.67 kB
react-native/implementations/ReactNativeRenderer-prod.fb.js = 278.86 kB 277.50 kB = 50.11 kB 49.87 kB
react-native/implementations/ReactNativeRenderer-prod.js = 278.83 kB 277.47 kB = 50.12 kB 49.89 kB
oss-stable-semver/react-test-renderer/umd/react-test-renderer.production.min.js = 79.83 kB 79.44 kB = 25.09 kB 24.99 kB
oss-stable/react-test-renderer/umd/react-test-renderer.production.min.js = 79.83 kB 79.44 kB = 25.09 kB 24.99 kB
react-native/implementations/ReactFabric-prod.fb.js = 272.47 kB 271.10 kB = 48.80 kB 48.57 kB
react-native/implementations/ReactFabric-prod.js = 272.42 kB 271.05 kB = 48.80 kB 48.58 kB
oss-experimental/react-reconciler/cjs/react-reconciler.profiling.min.js = 100.89 kB 100.39 kB = 31.14 kB 30.99 kB
oss-stable-semver/react-reconciler/cjs/react-reconciler.profiling.min.js = 96.63 kB 96.13 kB = 29.78 kB 29.58 kB
oss-stable/react-reconciler/cjs/react-reconciler.profiling.min.js = 96.63 kB 96.13 kB = 29.78 kB 29.58 kB
facebook-react-native/react-test-renderer/cjs/ReactTestRenderer-profiling.js = 253.92 kB 252.57 kB = 46.29 kB 46.06 kB
oss-experimental/react-reconciler/cjs/react-reconciler.production.min.js = 93.47 kB 92.96 kB = 28.88 kB 28.75 kB
oss-stable-semver/react-reconciler/cjs/react-reconciler.production.min.js = 91.02 kB 90.51 kB = 28.12 kB 27.96 kB
oss-stable/react-reconciler/cjs/react-reconciler.production.min.js = 91.02 kB 90.51 kB = 28.12 kB 27.96 kB
facebook-react-native/react-test-renderer/cjs/ReactTestRenderer-prod.js = 239.22 kB 237.86 kB = 44.04 kB 43.82 kB

Generated by 🚫 dangerJS against 626cd53

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@gaearon
Remove the safeguard around beforeActiveInstanceBlur
626cd53
bvaughn
bvaughn reviewed Jun 11, 2021
View reviewed changes
Comment thread packages/react-reconciler/src/ReactFiberCommitWork.new.js
function commitBeforeMutationEffectsOnFiber(finishedWork: Fiber) {
const current = finishedWork.alternate;
const flags = finishedWork.flags;
setCurrentDebugFiberInDEV(finishedWork);

@bvaughn bvaughn Jun 11, 2021

Copy link
Copy Markdown
Contributor

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 don't think I like the removal of the Snapshot flag check around the switch statement. It seems a little weird to call a method that does not sound (but happens to be ) snapshot-specific (commitBeforeMutationEffectsOnFiber) and then do work without checking in that method.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@bvaughn bvaughn Jun 11, 2021

Copy link
Copy Markdown
Contributor

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.

Can we add the outer check (so we don't do the guarded callback unnecessarily) and leave the inner check?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@gaearon gaearon Jun 11, 2021

Copy link
Copy Markdown
Collaborator Author

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 was looking at commitPassiveMountOnFiber which has the check outside. Overall I think there's some tension in this code between having generic naming and avoiding too many guards. I don't know what's a great way to balance but repeating the same check twice in a hot path also seems non-ideal?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@bvaughn bvaughn Jun 11, 2021

Copy link
Copy Markdown
Contributor

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.

Agreed. My initial impression was that moving the check outside was not great (b'c less clear) but I see what you're saying too. I don't have strong feelings.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@acdlite acdlite Jun 15, 2021

Copy link
Copy Markdown
Collaborator

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.

Most fibers do not have a Snapshot flag set. It's a rare case. So with the guard, the most common case is a single check, then you bail out. Without the guard, you have to do at least one check (the switch case) then additional checks for some branches (like class components).

So I would add back the Snapshot check.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@acdlite acdlite Jun 15, 2021

Copy link
Copy Markdown
Collaborator

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.

Oh there's a check in the outer function. Nvm, didn't see that part.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bvaughn

bvaughn commented Jun 11, 2021

Copy link
Copy Markdown
Contributor

Diff between two branches (easiest way to review IMO):
https://github.com/gaearon/react/compare/eh-flag...igc?w=1

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@gaearon gaearon mentioned this pull request Jun 11, 2021
Remove invokeGuardedCallback from commit phase #21666
Merged
acdlite
acdlite reviewed Jun 15, 2021
View reviewed changes
Comment thread packages/react-reconciler/src/ReactFiberCommitWork.new.js
commitMutationEffectsOnFiber(fiber, root);
} catch (error) {
captureCommitPhaseError(fiber, fiber.return, error);
if (fiber.flags !== NoFlags) {

@acdlite acdlite Jun 15, 2021

Copy link
Copy Markdown
Collaborator

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.

Suggested change
if (fiber.flags !== NoFlags) {
if ((fiber.flags & MutationMask) !== NoFlags) {

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
acdlite
acdlite approved these changes Jun 15, 2021
View reviewed changes

@acdlite acdlite left a comment

Copy link
Copy Markdown
Collaborator

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.

Just the one nit, LGTM

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@acdlite

acdlite commented Jun 15, 2021

Copy link
Copy Markdown
Collaborator

Oh haha I didn't see #21666. Even better!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@acdlite acdlite closed this Jun 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@acdlite acdlite acdlite approved these changes
+1 more reviewer
@bvaughn bvaughn bvaughn left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

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

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@gaearon @sizebot @bvaughn @acdlite @facebook-github-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.