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

Extract queueing logic into shared functions #22452

Merged
merged 1 commit into from
Sep 28, 2021

Conversation

acdlite
Copy link
Collaborator

@acdlite acdlite commented Sep 28, 2021

As a follow up to #22445, this extracts the queueing logic that is shared between dispatchSetState and dispatchReducerAction into separate functions. It likely doesn't save any bytes since these will get inlined, anyway, but it does make the flow a bit easier to follow.

As a follow up to facebook#22445, this extracts the queueing logic that is
shared between `dispatchSetState` and `dispatchReducerAction` into
separate functions. It likely doesn't save any bytes since these will
get inlined, anyway, but it does make the flow a bit easier to follow.
@facebook-github-bot facebook-github-bot added the React Core Team Opened by a member of the React Core Team label Sep 28, 2021
@sizebot
Copy link

sizebot commented Sep 28, 2021

Comparing: 6638815...224290c

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 = 130.40 kB 130.22 kB = 41.53 kB 41.45 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js = 133.23 kB 133.04 kB = 42.48 kB 42.42 kB
facebook-www/ReactDOM-prod.classic.js = 413.15 kB 412.58 kB +0.03% 76.35 kB 76.37 kB
facebook-www/ReactDOM-prod.modern.js = 401.78 kB 401.21 kB +0.04% 74.64 kB 74.67 kB
facebook-www/ReactDOMForked-prod.classic.js = 413.15 kB 412.58 kB +0.03% 76.35 kB 76.37 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
react-native/implementations/ReactNativeRenderer-profiling.js = 303.15 kB 302.54 kB = 54.19 kB 54.18 kB
react-native/implementations/ReactFabric-profiling.fb.js = 302.16 kB 301.55 kB = 54.03 kB 54.01 kB
react-native/implementations/ReactFabric-profiling.js = 294.59 kB 293.98 kB = 52.54 kB 52.51 kB
facebook-www/ReactART-prod.classic.js = 269.86 kB 269.29 kB +0.06% 48.04 kB 48.07 kB
react-native/implementations/ReactNativeRenderer-prod.fb.js = 288.03 kB 287.42 kB = 51.93 kB 51.91 kB
oss-experimental/react-art/cjs/react-art.production.min.js = 85.65 kB 85.47 kB = 26.56 kB 26.49 kB
react-native/implementations/ReactNativeRenderer-prod.js = 285.21 kB 284.60 kB = 51.26 kB 51.24 kB
react-native/implementations/ReactFabric-prod.fb.js = 284.23 kB 283.62 kB = 51.03 kB 51.00 kB
oss-experimental/react-test-renderer/umd/react-test-renderer.production.min.js = 82.60 kB 82.42 kB = 25.92 kB 25.84 kB
facebook-www/ReactART-prod.modern.js = 262.20 kB 261.63 kB +0.02% 46.82 kB 46.83 kB
oss-stable-semver/react-art/cjs/react-art.production.min.js = 83.26 kB 83.08 kB = 25.79 kB 25.70 kB
oss-stable/react-art/cjs/react-art.production.min.js = 83.26 kB 83.08 kB = 25.79 kB 25.70 kB
react-native/implementations/ReactFabric-prod.js = 276.68 kB 276.07 kB = 49.64 kB 49.62 kB
oss-stable-semver/react-test-renderer/umd/react-test-renderer.production.min.js = 80.22 kB 80.05 kB = 25.08 kB 24.99 kB
oss-stable/react-test-renderer/umd/react-test-renderer.production.min.js = 80.22 kB 80.05 kB = 25.08 kB 24.99 kB
oss-experimental/react-test-renderer/cjs/react-test-renderer.production.min.js = 82.42 kB 82.24 kB = 25.50 kB 25.42 kB
oss-stable-semver/react-test-renderer/cjs/react-test-renderer.production.min.js = 80.04 kB 79.86 kB = 24.76 kB 24.67 kB
oss-stable/react-test-renderer/cjs/react-test-renderer.production.min.js = 80.04 kB 79.86 kB = 24.76 kB 24.67 kB
oss-experimental/react-art/umd/react-art.development.js = 790.87 kB 789.00 kB = 166.48 kB 166.49 kB
facebook-react-native/react-test-renderer/cjs/ReactTestRenderer-profiling.js = 255.00 kB 254.39 kB = 46.37 kB 46.35 kB
oss-stable-semver/react-art/umd/react-art.development.js = 774.15 kB 772.27 kB = 163.08 kB 163.08 kB
oss-stable/react-art/umd/react-art.development.js = 774.15 kB 772.27 kB = 163.08 kB 163.08 kB
oss-experimental/react-reconciler/cjs/react-reconciler.development.js = 739.45 kB 737.63 kB +0.01% 156.76 kB 156.78 kB
oss-stable-semver/react-reconciler/cjs/react-reconciler.development.js = 723.38 kB 721.56 kB +0.01% 153.29 kB 153.31 kB
oss-stable/react-reconciler/cjs/react-reconciler.development.js = 723.38 kB 721.56 kB +0.01% 153.29 kB 153.31 kB
react-native/implementations/ReactNativeRenderer-dev.fb.js = 758.42 kB 756.52 kB = 163.53 kB 163.52 kB
facebook-react-native/react-test-renderer/cjs/ReactTestRenderer-prod.js = 240.42 kB 239.80 kB = 44.01 kB 43.95 kB
react-native/implementations/ReactFabric-dev.fb.js = 743.10 kB 741.19 kB = 160.12 kB 160.11 kB
react-native/implementations/ReactNativeRenderer-dev.js = 740.33 kB 738.42 kB = 160.23 kB 160.22 kB
react-native/implementations/ReactFabric-dev.js = 722.99 kB 721.08 kB = 156.37 kB 156.36 kB
oss-experimental/react-art/cjs/react-art.development.js = 685.86 kB 684.04 kB +0.01% 148.08 kB 148.10 kB
oss-stable-semver/react-art/cjs/react-art.development.js = 669.98 kB 668.16 kB +0.01% 144.68 kB 144.70 kB
oss-stable/react-art/cjs/react-art.development.js = 669.98 kB 668.16 kB +0.01% 144.68 kB 144.70 kB
facebook-www/ReactART-dev.classic.js = 735.21 kB 733.16 kB = 156.34 kB 156.35 kB
facebook-www/ReactART-dev.modern.js = 724.93 kB 722.88 kB = 154.19 kB 154.20 kB
oss-experimental/react-test-renderer/umd/react-test-renderer.development.js = 668.06 kB 666.11 kB = 140.23 kB 140.22 kB
facebook-www/ReactTestRenderer-dev.modern.js = 643.50 kB 641.60 kB = 137.65 kB 137.64 kB
facebook-www/ReactTestRenderer-dev.classic.js = 643.49 kB 641.58 kB = 137.64 kB 137.63 kB
oss-experimental/react-test-renderer/cjs/react-test-renderer.development.js = 636.92 kB 635.03 kB = 138.69 kB 138.69 kB
oss-stable-semver/react-test-renderer/umd/react-test-renderer.development.js = 651.37 kB 649.42 kB = 136.81 kB 136.81 kB
oss-stable/react-test-renderer/umd/react-test-renderer.development.js = 651.37 kB 649.42 kB = 136.81 kB 136.81 kB
facebook-react-native/react-test-renderer/cjs/ReactTestRenderer-dev.js = 632.09 kB 630.18 kB = 136.41 kB 136.39 kB
oss-stable-semver/react-test-renderer/cjs/react-test-renderer.development.js = 621.07 kB 619.18 kB = 135.31 kB 135.31 kB
oss-stable/react-test-renderer/cjs/react-test-renderer.development.js = 621.07 kB 619.18 kB = 135.31 kB 135.31 kB

Generated by 🚫 dangerJS against 224290c

Copy link
Contributor

@josephsavona josephsavona left a comment

Choose a reason for hiding this comment

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

Looks good to me. I left some comments with an alternate approach, but the suggestion is probably too much of a pain to do in Flow (I'm too used to Rust now).


if (__DEV__) {
// $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests
if ('undefined' !== typeof jest) {
warnIfNotCurrentlyActingUpdatesInDev(fiber);
}
}
const eventTime = requestEventTime();
Copy link
Contributor

Choose a reason for hiding this comment

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

i guess not that much work happens between where this call was and where it moved to, so the timing is still accurate enough?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah it doesn't need to be super precise, it's only used for starvation detection.

Comment on lines +2191 to +2192
if (root !== null) {
entangleTransitionUpdate(root, queue, lane);
Copy link
Contributor

Choose a reason for hiding this comment

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

One suggestion here: since entangleTransitionUpdate() immediately checks isTransitionLane(lane), it might be better to put the check outside and avoid calling the function unless isTransitionLane(lane) is true. Something like:

// Takes a lane, checks if its entangled, returns the lane as an opaque type wrapper if so
const entangledLane: EntangledLane | null = checkEntangledLane(lane);
if (entangedLand !== null) {
  // type of entangledLane is 
  // opaque type EntangledLane: Lane = Lane;
  entangleTransitionUpdate(root, queue, entangledLane);
}

This doesn't incur any overhead - entangedLane is still a number - but it uses types to enforce correct calling sequence. This also lets the JIT inline just checkEntangledLane(), and potentially avoid inlining the more rarely called entangleTransitionUpdate().

Maybe not worth it but figured i'd mention it.

Copy link
Collaborator Author

@acdlite acdlite Sep 28, 2021

Choose a reason for hiding this comment

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

Lane used to be an opaque type but I had to un-opaque it because it leaks outside of the reconciler via the Fiber type, unfortunately. And the Fiber type is shared between reconciler forks, so we would have had to fork literally every file in our repo (i.e. React DOM, too) which I was loath to do. Our Flow types for Fiber are kind of a mess, not even sure if it's possible to model correctly and if it were it would involve so much work that we might as well just go all the way to Rust.

Re: avoiding the function call, Closure inlines both of these functions anyway, but that's a good point. I had it that way at first but I moved it for symmetry with the equivalent class update queue function. I figure I'll hoist it out as soon as we need to put additional transition-only logic in there.

@acdlite acdlite merged commit d9fb383 into facebook:main Sep 28, 2021
facebook-github-bot pushed a commit to facebook/react-native that referenced this pull request Oct 12, 2021
Summary:
This sync includes the following changes:
- **[579c008a7](facebook/react@579c008a7 )**: [Fizz/Flight] pipeToNodeWritable(..., writable).startWriting() -> renderToPipeableStream(...).pipe(writable) ([#22450](facebook/react#22450)) //<Sebastian Markbåge>//
- **[f2c381131](facebook/react@f2c381131 )**: fix: useSyncExternalStoreExtra ([#22500](facebook/react#22500)) //<Daishi Kato>//
- **[0ecbbe142](facebook/react@0ecbbe142 )**: Sync hydrate discrete events in capture phase and dont replay discrete events ([#22448](facebook/react#22448)) //<salazarm>//
- **[a724a3b57](facebook/react@a724a3b57 )**: [RFC] Codemod invariant -> throw new Error ([#22435](facebook/react#22435)) //<Andrew Clark>//
- **[201af81b0](facebook/react@201af81b0 )**: Release pooled cache reference in complete/unwind ([#22464](facebook/react#22464)) //<Joseph Savona>//
- **[033efe731](facebook/react@033efe731 )**: Call get snapshot in useSyncExternalStore server shim ([#22453](facebook/react#22453)) //<salazarm>//
- **[7843b142a](facebook/react@7843b142a )**: [Fizz/Flight] Pass in Destination lazily to startFlowing instead of in createRequest ([#22449](facebook/react#22449)) //<Sebastian Markbåge>//
- **[d9fb383d6](facebook/react@d9fb383d6 )**: Extract queueing logic into shared functions ([#22452](facebook/react#22452)) //<Andrew Clark>//
- **[9175f4d15](facebook/react@9175f4d15 )**: Scheduling Profiler: Show Suspense resource .displayName ([#22451](facebook/react#22451)) //<Brian Vaughn>//
- **[eba248c39](facebook/react@eba248c39 )**: [Fizz/Flight] Remove reentrancy hack ([#22446](facebook/react#22446)) //<Sebastian Markbåge>//
- **[66388150e](facebook/react@66388150e )**: Remove usereducer eager bailout ([#22445](facebook/react#22445)) //<Joseph Savona>//
- **[d3e086932](facebook/react@d3e086932 )**: Make root.unmount() synchronous  ([#22444](facebook/react#22444)) //<Andrew Clark>//
- **[2cc6d79c9](facebook/react@2cc6d79c9 )**: Rename onReadyToStream to onCompleteShell ([#22443](facebook/react#22443)) //<Sebastian Markbåge>//
- **[c88fb49d3](facebook/react@c88fb49d3 )**: Improve DEV errors if string coercion throws (Temporal.*, Symbol, etc.) ([#22064](facebook/react#22064)) //<Justin Grant>//
- **[05726d72c](facebook/react@05726d72c )**: [Fix] Errors should not "unsuspend" a transition ([#22423](facebook/react#22423)) //<Andrew Clark>//
- **[3746eaf98](facebook/react@3746eaf98 )**: Packages/React/src/ReactLazy ---> changing -1 to unintialized ([#22421](facebook/react#22421)) //<BIKI DAS>//
- **[04ccc01d9](facebook/react@04ccc01d9 )**: Hydration errors should force a client render ([#22416](facebook/react#22416)) //<Andrew Clark>//
- **[029fdcebb](facebook/react@029fdcebb )**: root.hydrate -> root.isDehydrated ([#22420](facebook/react#22420)) //<Andrew Clark>//
- **[af87f5a83](facebook/react@af87f5a83 )**: Scheduling Profiler marks should include thrown Errors ([#22417](facebook/react#22417)) //<Brian Vaughn>//
- **[d47339ea3](facebook/react@d47339ea3 )**: [Fizz] Remove assignID mechanism ([#22410](facebook/react#22410)) //<Sebastian Markbåge>//
- **[3a50d9557](facebook/react@3a50d9557 )**: Never attach ping listeners in legacy Suspense ([#22407](facebook/react#22407)) //<Andrew Clark>//
- **[82c8fa90b](facebook/react@82c8fa90b )**: Add back useMutableSource temporarily ([#22396](facebook/react#22396)) //<Andrew Clark>//
- **[5b57bc6e3](facebook/react@5b57bc6e3 )**: [Draft] don't patch console during first render ([#22308](facebook/react#22308)) //<Luna Ruan>//
- **[cf07c3df1](facebook/react@cf07c3df1 )**: Delete all but one `build2` reference ([#22391](facebook/react#22391)) //<Andrew Clark>//
- **[bb0d06935](facebook/react@bb0d06935 )**: [build2 -> build] Local scripts //<Andrew Clark>//
- **[0c81d347b](facebook/react@0c81d347b )**: Write artifacts to `build` instead of `build2` //<Andrew Clark>//
- **[4da03c9fb](facebook/react@4da03c9fb )**: useSyncExternalStore React Native version ([#22367](facebook/react#22367)) //<salazarm>//
- **[48d475c9e](facebook/react@48d475c9e )**: correct typos ([#22294](facebook/react#22294)) //<Bowen>//
- **[cb6c619c0](facebook/react@cb6c619c0 )**: Remove Fiber fields that were used for hydrating useMutableSource ([#22368](facebook/react#22368)) //<Sebastian Silbermann>//
- **[64e70f82e](facebook/react@64e70f82e )**: [Fizz] add avoidThisFallback support ([#22318](facebook/react#22318)) //<salazarm>//
- **[3ee7a004e](facebook/react@3ee7a004e )**: devtools: Display actual ReactDOM API name in root type ([#22363](facebook/react#22363)) //<Sebastian Silbermann>//
- **[79b8fc667](facebook/react@79b8fc667 )**: Implement getServerSnapshot in userspace shim ([#22359](facebook/react#22359)) //<Andrew Clark>//
- **[86b3e2461](facebook/react@86b3e2461 )**: Implement useSyncExternalStore on server ([#22347](facebook/react#22347)) //<Andrew Clark>//
- **[8209de269](facebook/react@8209de269 )**: Delete useMutableSource implementation ([#22292](facebook/react#22292)) //<Andrew Clark>//

Changelog:
[General][Changed] - React Native sync for revisions e8feb11...afcb9cd

jest_e2e[run_all_tests]

Reviewed By: yungsters

Differential Revision: D31541359

fbshipit-source-id: c35941bc303fdf55cb061e9996200dc868a6f2af
zhengjitf pushed a commit to zhengjitf/react that referenced this pull request Apr 15, 2022
As a follow up to facebook#22445, this extracts the queueing logic that is
shared between `dispatchSetState` and `dispatchReducerAction` into
separate functions. It likely doesn't save any bytes since these will
get inlined, anyway, but it does make the flow a bit easier to follow.
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