Skip to content

Split Update flag into a mutation and effect flag #27533

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

Closed
wants to merge 1 commit into from

Conversation

kassens
Copy link
Member

@kassens kassens commented Oct 17, 2023

The Update flag was overloaded to mean that there's "work to do during the commit phase". On the one side that was updates to host components. On the other side that meant running effects.

The flag was also used in persistent mode to trigger cloning the immutable view hierarchy to perform the updates. When the flag was only used to indicate calling effects, this meant needlessly cloning the subtree.

Here we start splitting up the flag into 2. In the transition phase we set both flags in some places, but most likey every location should only set or check one of the flags.

The `Update` flag was overloaded to mean that there's "work to do during the commit phase".
On the one side that was updates to host components. On the other side that meant running
effects.

The flag was also used in persistent mode to trigger cloning the immutable view hierarchy to
perform the updates. When the flag was only used to indicate calling effects, this meant
needlessly cloning the subtree.

Here we *start* splitting up the flag into 2. In the transition phase we set both flags in
some places, but most likey every location should only set or check one of the flags.
@kassens kassens requested review from javache and acdlite October 17, 2023 14:08
@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Oct 17, 2023
@react-sizebot
Copy link

Comparing: 67cc9ba...fc3ac3a

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 +0.15% 174.68 kB 174.94 kB +0.05% 54.32 kB 54.34 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js +0.16% 176.77 kB 177.04 kB +0.06% 54.99 kB 55.03 kB
facebook-www/ReactDOM-prod.classic.js +0.07% 565.55 kB 565.95 kB +0.07% 99.53 kB 99.60 kB
facebook-www/ReactDOM-prod.modern.js +0.07% 549.40 kB 549.81 kB +0.08% 96.60 kB 96.68 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-reconciler/cjs/react-reconciler.profiling.min.js +0.26% 125.80 kB 126.13 kB +0.17% 37.86 kB 37.93 kB
oss-stable-semver/react-reconciler/cjs/react-reconciler.profiling.min.js +0.25% 123.89 kB 124.20 kB +0.17% 37.18 kB 37.24 kB
oss-stable/react-reconciler/cjs/react-reconciler.profiling.min.js +0.25% 123.92 kB 124.23 kB +0.17% 37.20 kB 37.26 kB
oss-experimental/react-reconciler/cjs/react-reconciler.production.min.js +0.24% 116.78 kB 117.06 kB +0.12% 35.60 kB 35.64 kB
oss-stable-semver/react-reconciler/cjs/react-reconciler.production.min.js +0.23% 114.86 kB 115.13 kB +0.12% 34.97 kB 35.01 kB
oss-stable/react-reconciler/cjs/react-reconciler.production.min.js +0.23% 114.89 kB 115.16 kB +0.12% 34.99 kB 35.04 kB
oss-experimental/react-art/cjs/react-art.production.min.js +0.23% 99.91 kB 100.13 kB +0.14% 30.63 kB 30.67 kB
oss-stable-semver/react-art/cjs/react-art.production.min.js +0.22% 98.01 kB 98.22 kB +0.16% 30.04 kB 30.09 kB
oss-stable/react-art/cjs/react-art.production.min.js +0.22% 98.06 kB 98.27 kB +0.16% 30.07 kB 30.12 kB

Generated by 🚫 dangerJS against fc3ac3a

}));

const ComponentWithEffect = () => {
// Same thing happens with `ref` and `useImperativeHandle`
Copy link
Member

Choose a reason for hiding this comment

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

Worth testing that ref / useImperativeHandle now pass this test too?

Copy link
Collaborator

@acdlite acdlite left a comment

Choose a reason for hiding this comment

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

I think a better overall approach would be to add a flag that represents something that has been cloned. Call it Cloned or something.

It would only be set in persistent mode, not mutation mode, and it would accompany any call to cloneInstance, cloneText, et al.

Then you can update this function to check for Cloned instead of MutationMask:

(child.flags & MutationMask) !== NoFlags ||
(child.subtreeFlags & MutationMask) !== NoFlags

I think this would be simpler because it's less likely the meanings of the flags will get overloaded again.

@kassens
Copy link
Member Author

kassens commented Oct 25, 2023

@acdlite Our thought for further splitting of this flag was that we could potentially safe some traversal down if only host components are updated, but other update effects aren't in place. Is that assumption wrong and we basically always have the (non-clone) effect set if there would be a "cloned" flag set?

@kassens
Copy link
Member Author

kassens commented Nov 9, 2023

Superseded by #27647

@kassens kassens closed this Nov 9, 2023
@kassens kassens deleted the persistent-update2 branch November 9, 2023 17:01
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