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

Move Current Owner (and Cache) to an Async Dispatcher #28798

Closed
wants to merge 10 commits into from

Conversation

sebmarkbage
Copy link
Collaborator

Current Owner inside an Async Component will need to be tracked using AsyncLocalStorage. This is similar to how cache() works.

Sooner or later we'll have to start tracking AsyncContext in the isomorphic package because startTransition(async) needs it. Since the transition config needs to be tracked asynchronously too. However, we can reasonably only do that once it's actually shipping in all browsers pretty much. I.e. not soon.

The way we do this with cache() (and Float in the DOM package) is by delegating it to a dispatcher that can be alive for longer and then within that dispatcher use an environment specific context to track that renderer's internal state.

This renames the CacheDispatcher to the more generic AsyncDispatcher and add a getOwner method on it. Then we track the actual state of the owner inside of each renderer. This doesn't yet track the owner asynchronously in Flight but I'll do that part in a follow up.

@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Apr 9, 2024
@sebmarkbage sebmarkbage force-pushed the asynccurrentowner branch 2 times, most recently from 0e3f7a6 to c49a5df Compare April 9, 2024 18:51
@react-sizebot
Copy link

react-sizebot commented Apr 9, 2024

Comparing: 699d03c...fac727f

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.16 kB +0.01% 103.91 kB 103.92 kB
facebook-www/ReactDOM-prod.modern.js = 566.95 kB 566.97 kB +0.01% 100.12 kB 100.14 kB
facebook-react-native/react/cjs/JSXRuntime-prod.js +4.30% 2.86 kB 2.98 kB +3.43% 1.23 kB 1.27 kB
facebook-react-native/react/cjs/JSXRuntime-profiling.js +4.30% 2.86 kB 2.98 kB +3.43% 1.23 kB 1.27 kB
oss-experimental/react-suspense-test-utils/cjs/react-suspense-test-utils.js +4.18% 1.17 kB 1.22 kB +2.58% 0.58 kB 0.60 kB
oss-stable-semver/react-suspense-test-utils/cjs/react-suspense-test-utils.js +4.18% 1.17 kB 1.22 kB +2.58% 0.58 kB 0.60 kB
oss-stable/react-suspense-test-utils/cjs/react-suspense-test-utils.js +4.18% 1.17 kB 1.22 kB +2.58% 0.58 kB 0.60 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
facebook-react-native/react/cjs/JSXRuntime-prod.js +4.30% 2.86 kB 2.98 kB +3.43% 1.23 kB 1.27 kB
facebook-react-native/react/cjs/JSXRuntime-profiling.js +4.30% 2.86 kB 2.98 kB +3.43% 1.23 kB 1.27 kB
oss-experimental/react-suspense-test-utils/cjs/react-suspense-test-utils.js +4.18% 1.17 kB 1.22 kB +2.58% 0.58 kB 0.60 kB
oss-stable-semver/react-suspense-test-utils/cjs/react-suspense-test-utils.js +4.18% 1.17 kB 1.22 kB +2.58% 0.58 kB 0.60 kB
oss-stable/react-suspense-test-utils/cjs/react-suspense-test-utils.js +4.18% 1.17 kB 1.22 kB +2.58% 0.58 kB 0.60 kB
oss-experimental/react/cjs/react-jsx-dev-runtime.development.js +0.31% 41.28 kB 41.41 kB +0.35% 12.47 kB 12.52 kB
oss-stable-semver/react/cjs/react-jsx-dev-runtime.development.js +0.31% 41.28 kB 41.41 kB +0.35% 12.47 kB 12.52 kB
oss-stable/react/cjs/react-jsx-dev-runtime.development.js +0.31% 41.28 kB 41.41 kB +0.35% 12.47 kB 12.52 kB
oss-experimental/react/cjs/react-jsx-runtime.development.js +0.30% 42.51 kB 42.64 kB +0.33% 12.82 kB 12.86 kB
oss-stable-semver/react/cjs/react-jsx-runtime.development.js +0.30% 42.51 kB 42.64 kB +0.33% 12.82 kB 12.86 kB
oss-stable/react/cjs/react-jsx-runtime.development.js +0.30% 42.51 kB 42.64 kB +0.33% 12.82 kB 12.86 kB
oss-experimental/react/cjs/react-jsx-runtime.react-server.development.js +0.25% 42.94 kB 43.05 kB +0.32% 12.94 kB 12.99 kB
oss-stable-semver/react/cjs/react-jsx-runtime.react-server.development.js +0.25% 42.94 kB 43.05 kB +0.32% 12.94 kB 12.99 kB
oss-stable/react/cjs/react-jsx-runtime.react-server.development.js +0.25% 42.94 kB 43.05 kB +0.32% 12.94 kB 12.99 kB
oss-experimental/react/cjs/react.react-server.production.js = 20.89 kB 20.81 kB = 5.54 kB 5.53 kB
oss-experimental/react/cjs/react.production.js = 18.09 kB 18.01 kB = 4.69 kB 4.68 kB
oss-stable/react/cjs/react.react-server.production.js = 17.26 kB 17.18 kB = 4.70 kB 4.69 kB
oss-stable-semver/react/cjs/react.react-server.production.js = 17.24 kB 17.16 kB = 4.67 kB 4.66 kB
oss-stable/react/cjs/react.production.js = 16.97 kB 16.89 kB = 4.43 kB 4.42 kB
oss-stable-semver/react/cjs/react.production.js = 16.95 kB 16.87 kB = 4.41 kB 4.39 kB
facebook-www/React-profiling.classic.js = 23.29 kB 23.12 kB = 5.93 kB 5.92 kB
facebook-www/React-profiling.modern.js = 23.29 kB 23.12 kB = 5.93 kB 5.92 kB
facebook-www/React-prod.classic.js = 22.86 kB 22.68 kB = 5.85 kB 5.84 kB
facebook-www/React-prod.modern.js = 22.86 kB 22.68 kB = 5.85 kB 5.84 kB
oss-experimental/react/cjs/react-jsx-runtime.production.js = 0.99 kB 0.98 kB = 0.51 kB 0.50 kB
oss-stable-semver/react/cjs/react-jsx-runtime.production.js = 0.99 kB 0.98 kB = 0.51 kB 0.50 kB
oss-stable/react/cjs/react-jsx-runtime.production.js = 0.99 kB 0.98 kB = 0.51 kB 0.50 kB
oss-experimental/react/cjs/react-jsx-runtime.profiling.js = 0.99 kB 0.98 kB = 0.51 kB 0.50 kB
oss-stable-semver/react/cjs/react-jsx-runtime.profiling.js = 0.99 kB 0.98 kB = 0.51 kB 0.50 kB
oss-stable/react/cjs/react-jsx-runtime.profiling.js = 0.99 kB 0.98 kB = 0.51 kB 0.50 kB
test_utils/ReactAllWarnings.js Deleted 64.80 kB 0.00 kB Deleted 16.14 kB 0.00 kB

Generated by 🚫 dangerJS against fac727f

@josephsavona
Copy link
Contributor

Just landed #28797 so this will need a quick rebase

T: null | BatchConfigTransition, // ReactCurrentBatchConfig for Transitions

// DEV-only-ish
owner: null | Fiber, // ReactCurrentOwner is Fiber on the Client, null in Fizz. Flight uses SharedStateServer.
Copy link
Member

Choose a reason for hiding this comment

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

We still need this I think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What do you mean? It's replaced by A.getOwner()

Basically always but we currently don't actually need it for prod on the
client.
This means that usage internal to the reconciler can refer to it directly
without going through the dispatcher.
This will later use AsyncLocalStorage to track this just like the cache.
We need to be careful about only getting it in branches that has the dispatcher
activated and if the dispatcher is activate.
gnoff added a commit that referenced this pull request Apr 25, 2024
…28912)

Rebasing and landing #28798

This PR was approved already but held back to give time for the sync.
Rebased and landing here without pushing to seb's remote to avoid
possibility of lost updates

---------

Co-authored-by: Sebastian Markbage <sebastian@calyptus.eu>
github-actions bot pushed a commit that referenced this pull request Apr 25, 2024
…28912)

Rebasing and landing #28798

This PR was approved already but held back to give time for the sync.
Rebased and landing here without pushing to seb's remote to avoid
possibility of lost updates

---------

Co-authored-by: Sebastian Markbage <sebastian@calyptus.eu>

DiffTrain build for commit 94eed63.
github-actions bot pushed a commit that referenced this pull request Apr 25, 2024
…28912)

Rebasing and landing #28798

This PR was approved already but held back to give time for the sync.
Rebased and landing here without pushing to seb's remote to avoid
possibility of lost updates

---------

Co-authored-by: Sebastian Markbage <sebastian@calyptus.eu>

DiffTrain build for [94eed63](94eed63)
@gnoff
Copy link
Collaborator

gnoff commented Apr 25, 2024

landed in #28912

@gnoff gnoff closed this Apr 25, 2024
sebmarkbage added a commit that referenced this pull request May 3, 2024
Stacked on #28798.

Add another AsyncLocalStorage to the FlightServerConfig. This context
tracks data on a per component level. Currently the only thing we track
is the owner in DEV.

AsyncLocalStorage around each component comes with a performance cost so
we only do it DEV. It's not generally a particularly safe operation
because you can't necessarily associate side-effects with a component
based on execution scope. It can be a lazy initializer or cache():ed
code etc. We also don't support string refs anymore for a reason.

However, it's good enough for optional dev only information like the
owner.
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.

None yet

6 participants