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

(cherrypick b09e102f) [Fizz] Prevent uncloned large precomputed chunks without relying on render-time assertions #28580 #28585

Merged
merged 1 commit into from
Mar 19, 2024

Conversation

gnoff
Copy link
Collaborator

@gnoff gnoff commented Mar 19, 2024

(cherrypick b09e102 on 60a927d)

[Fizz] Prevent uncloned large precomputed chunks without relying on render-time assertions (#28568)

A while back we implemented a heuristic that if a chunk was large it was assumed to be produced by the render and thus was safe to stream which results in transferring the underlying object memory. Later we ran into an issue where a precomputed chunk grew large enough to trigger this hueristic and it started causing renders to fail because once a second render had occurred the precomputed chunk would not have an underlying buffer of bytes to send and these bytes would be omitted from the stream. We implemented a technique to detect large precomputed chunks and we enforced that these always be cloned before writing. Unfortunately our test coverage was not perfect and there has been for a very long time now a usage pattern where if you complete a boundary in one flush and then complete a boundary that has stylehsheet dependencies in another flush you can get a large precomputed chunk that was not being cloned to be sent twice causing streaming errors.

I've thought about why we even went with this solution in the first place and I think it was a mistake. It relies on a dev only check to catch paired with potentially version specific order of operations on the streaming side. This is too unreliable. Additionally the low limit of view size for Edge is not used in Node.js but there is not real justification for this.

In this change I updated the view size for edge streaming to match Node at 2048 bytes which is still relatively small and we have no data one way or another to preference 512 over this. Then I updated the assertion logic to error anytime a precomputed chunk exceeds the size. This eliminates the need to clone these chunks by just making sure our view size is always larger than the largest precomputed chunk we can possibly write. I'm generally in favor of this for a few reasons.

First, we'll always know during testing whether we've violated the limit as long as we exercise each stream config because the precomputed chunks are created in module scope. Second, we can always split up large chunks so making sure the precomptued chunk is smaller than whatever view size we actually desire is relatively trivial.

…ender-time assertions (facebook#28568)

A while back we implemented a heuristic that if a chunk was large it was
assumed to be produced by the render and thus was safe to stream which
results in transferring the underlying object memory. Later we ran into
an issue where a precomputed chunk grew large enough to trigger this
hueristic and it started causing renders to fail because once a second
render had occurred the precomputed chunk would not have an underlying
buffer of bytes to send and these bytes would be omitted from the
stream. We implemented a technique to detect large precomputed chunks
and we enforced that these always be cloned before writing.
Unfortunately our test coverage was not perfect and there has been for a
very long time now a usage pattern where if you complete a boundary in
one flush and then complete a boundary that has stylehsheet dependencies
in another flush you can get a large precomputed chunk that was not
being cloned to be sent twice causing streaming errors.

I've thought about why we even went with this solution in the first
place and I think it was a mistake. It relies on a dev only check to
catch paired with potentially version specific order of operations on
the streaming side. This is too unreliable. Additionally the low limit
of view size for Edge is not used in Node.js but there is not real
justification for this.

In this change I updated the view size for edge streaming to match Node
at 2048 bytes which is still relatively small and we have no data one
way or another to preference 512 over this. Then I updated the assertion
logic to error anytime a precomputed chunk exceeds the size. This
eliminates the need to clone these chunks by just making sure our view
size is always larger than the largest precomputed chunk we can possibly
write. I'm generally in favor of this for a few reasons.

First, we'll always know during testing whether we've violated the limit
as long as we exercise each stream config because the precomputed chunks
are created in module scope. Second, we can always split up large chunks
so making sure the precomptued chunk is smaller than whatever view size
we actually desire is relatively trivial.
@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Mar 19, 2024
@gnoff gnoff merged commit 4b84f11 into facebook:sync-nextjs Mar 19, 2024
2 of 23 checks passed
@gnoff gnoff deleted the sync-nextjs branch March 19, 2024 01:01
@react-sizebot
Copy link

Comparing: 60a927d...0a8846d

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 = 176.19 kB 176.19 kB = 54.88 kB 54.88 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js = 178.29 kB 178.29 kB = 55.53 kB 55.53 kB
facebook-www/ReactDOM-prod.classic.js = 571.89 kB 571.89 kB = 100.56 kB 100.56 kB
facebook-www/ReactDOM-prod.modern.js = 555.65 kB 555.65 kB = 97.63 kB 97.63 kB
oss-experimental/react-noop-renderer/cjs/react-noop-renderer-flight-server.production.js = 2.23 kB 2.18 kB = 0.89 kB 0.88 kB
oss-stable-semver/react-noop-renderer/cjs/react-noop-renderer-flight-server.production.js = 2.23 kB 2.18 kB = 0.89 kB 0.88 kB
oss-stable/react-noop-renderer/cjs/react-noop-renderer-flight-server.production.js = 2.23 kB 2.18 kB = 0.89 kB 0.88 kB
oss-experimental/react-noop-renderer/cjs/react-noop-renderer-flight-server.development.js = 2.47 kB 2.40 kB = 0.94 kB 0.93 kB
oss-stable-semver/react-noop-renderer/cjs/react-noop-renderer-flight-server.development.js = 2.47 kB 2.40 kB = 0.94 kB 0.93 kB
oss-stable/react-noop-renderer/cjs/react-noop-renderer-flight-server.development.js = 2.47 kB 2.40 kB = 0.94 kB 0.93 kB
oss-experimental/react-noop-renderer/cjs/react-noop-renderer-flight-server.production.min.js = 1.36 kB 1.31 kB = 0.63 kB 0.62 kB
oss-stable-semver/react-noop-renderer/cjs/react-noop-renderer-flight-server.production.min.js = 1.36 kB 1.31 kB = 0.63 kB 0.62 kB
oss-stable/react-noop-renderer/cjs/react-noop-renderer-flight-server.production.min.js = 1.36 kB 1.31 kB = 0.63 kB 0.62 kB
test_utils/ReactAllWarnings.js Deleted 67.55 kB 0.00 kB Deleted 16.54 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
oss-experimental/react-server-dom-webpack/umd/react-server-dom-webpack-server.browser.development.js = 124.67 kB 124.19 kB = 28.48 kB 28.35 kB
oss-experimental/react-server-dom-turbopack/umd/react-server-dom-turbopack-server.browser.development.js = 121.95 kB 121.47 kB = 27.75 kB 27.62 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.development.js = 118.88 kB 118.41 kB = 28.38 kB 28.26 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.development.js = 118.02 kB 117.56 kB = 28.07 kB 27.94 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.development.js = 123.84 kB 123.35 kB = 29.29 kB 29.15 kB
oss-experimental/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.edge.development.js = 116.82 kB 116.35 kB = 27.81 kB 27.68 kB
oss-experimental/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.node.development.js = 121.42 kB 120.93 kB = 28.61 kB 28.47 kB
oss-experimental/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.browser.development.js = 115.44 kB 114.97 kB = 27.34 kB 27.22 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.unbundled.development.js = 121.20 kB 120.71 kB = 28.40 kB 28.26 kB
oss-experimental/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.node.unbundled.development.js = 118.78 kB 118.29 kB = 27.76 kB 27.62 kB
oss-stable-semver/react-server-dom-webpack/umd/react-server-dom-webpack-server.browser.development.js = 110.57 kB 110.09 kB = 25.52 kB 25.38 kB
oss-stable/react-server-dom-webpack/umd/react-server-dom-webpack-server.browser.development.js = 110.57 kB 110.09 kB = 25.52 kB 25.38 kB
oss-experimental/react-server-dom-esm/cjs/react-server-dom-esm-server.node.development.js = 113.37 kB 112.87 kB = 26.55 kB 26.40 kB
oss-stable-semver/react-server-dom-turbopack/umd/react-server-dom-turbopack-server.browser.development.js = 107.85 kB 107.37 kB = 24.78 kB 24.64 kB
oss-stable/react-server-dom-turbopack/umd/react-server-dom-turbopack-server.browser.development.js = 107.85 kB 107.37 kB = 24.78 kB 24.64 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.development.js = 110.23 kB 109.74 kB = 26.32 kB 26.18 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.development.js = 110.23 kB 109.74 kB = 26.32 kB 26.18 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.development.js = 104.80 kB 104.34 kB = 25.20 kB 25.07 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.development.js = 104.80 kB 104.34 kB = 25.20 kB 25.07 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.development.js = 104.62 kB 104.15 kB = 25.17 kB 25.03 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.development.js = 104.62 kB 104.15 kB = 25.17 kB 25.03 kB
oss-stable-semver/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.edge.development.js = 102.74 kB 102.27 kB = 24.65 kB 24.51 kB
oss-stable/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.edge.development.js = 102.74 kB 102.27 kB = 24.65 kB 24.51 kB
oss-stable-semver/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.node.development.js = 107.82 kB 107.32 kB = 25.66 kB 25.51 kB
oss-stable/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.node.development.js = 107.82 kB 107.32 kB = 25.66 kB 25.51 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.unbundled.development.js = 107.60 kB 107.11 kB = 25.44 kB 25.30 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.unbundled.development.js = 107.60 kB 107.11 kB = 25.44 kB 25.30 kB
oss-stable-semver/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.browser.development.js = 102.04 kB 101.57 kB = 24.44 kB 24.31 kB
oss-stable/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.browser.development.js = 102.04 kB 101.57 kB = 24.44 kB 24.31 kB
oss-stable-semver/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.node.unbundled.development.js = 105.17 kB 104.68 kB = 24.81 kB 24.67 kB
oss-stable/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.node.unbundled.development.js = 105.17 kB 104.68 kB = 24.81 kB 24.67 kB
oss-stable-semver/react-server-dom-esm/cjs/react-server-dom-esm-server.node.development.js = 99.76 kB 99.27 kB = 23.60 kB 23.46 kB
oss-stable/react-server-dom-esm/cjs/react-server-dom-esm-server.node.development.js = 99.76 kB 99.27 kB = 23.60 kB 23.46 kB
oss-experimental/react-noop-renderer/cjs/react-noop-renderer-flight-server.production.js = 2.23 kB 2.18 kB = 0.89 kB 0.88 kB
oss-stable-semver/react-noop-renderer/cjs/react-noop-renderer-flight-server.production.js = 2.23 kB 2.18 kB = 0.89 kB 0.88 kB
oss-stable/react-noop-renderer/cjs/react-noop-renderer-flight-server.production.js = 2.23 kB 2.18 kB = 0.89 kB 0.88 kB
oss-experimental/react-noop-renderer/cjs/react-noop-renderer-flight-server.development.js = 2.47 kB 2.40 kB = 0.94 kB 0.93 kB
oss-stable-semver/react-noop-renderer/cjs/react-noop-renderer-flight-server.development.js = 2.47 kB 2.40 kB = 0.94 kB 0.93 kB
oss-stable/react-noop-renderer/cjs/react-noop-renderer-flight-server.development.js = 2.47 kB 2.40 kB = 0.94 kB 0.93 kB
oss-experimental/react-noop-renderer/cjs/react-noop-renderer-flight-server.production.min.js = 1.36 kB 1.31 kB = 0.63 kB 0.62 kB
oss-stable-semver/react-noop-renderer/cjs/react-noop-renderer-flight-server.production.min.js = 1.36 kB 1.31 kB = 0.63 kB 0.62 kB
oss-stable/react-noop-renderer/cjs/react-noop-renderer-flight-server.production.min.js = 1.36 kB 1.31 kB = 0.63 kB 0.62 kB
test_utils/ReactAllWarnings.js Deleted 67.55 kB 0.00 kB Deleted 16.54 kB 0.00 kB

Generated by 🚫 dangerJS against 0a8846d

ztanner added a commit to vercel/next.js that referenced this pull request Mar 19, 2024
Updates React from 60a927d04 to 4b84f1161.

### React upstream changes

- facebook/react#28585

Closes NEXT-2865
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.

3 participants