Skip to content

Conversation

@sebmarkbage
Copy link
Collaborator

@sebmarkbage sebmarkbage commented Oct 28, 2025

IO tasks can execute more than once. E.g. a connection may fire each time a new message or chunk comes in or a setInterval every time it executes.

We used to treat these all as one I/O node and just updated the end time as we go. Most of the time this was fine because typically you would have a Promise instance whose end time is really the one that gets used as the I/O anyway.

However, in a pattern like this it could be problematic:

setTimeout(() => {
  function App() {
    return Promise.resolve(123);
  }
  renderToReadableStream(<App />);
});

Because the I/O's end time is before the render started so it should be excluded from being considered I/O as part of the render. It happened outside of render. But because the Promise.resolve() is inside render its end time is after the render start so the promise is considered part of the render. This is usually not a problem because the end time of the I/O is still before the start of the render so even though the Promise is valid it has no I/O source so it's properly excluded.

However, if the I/O's end time updates before we observe this then the I/O can be considered part of the render. E.g. if this was a setInterval it would be clearly wrong. But it turns out that even setTimeout can sometimes execute more than once in the async_hooks because each run of "process.nextTick" and microtasks respectively are ran in their own before/after. When a micro task executes after this main body it'll update the end time which can then turn the whole I/O as being inside the render.

To solve this properly I create a new I/O node each time before() is invoked so that each one gets to observe a different end time. This has a potential CPU and memory allocation cost when there's a lot of them like in a quick stream.

@meta-cla meta-cla bot added the CLA Signed label Oct 28, 2025
@github-actions github-actions bot added the React Core Team Opened by a member of the React Core Team label Oct 28, 2025
@react-sizebot
Copy link

Comparing: fb0d960...edf4dd5

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 = 6.68 kB 6.68 kB = 1.83 kB 1.83 kB
oss-stable/react-dom/cjs/react-dom-client.production.js = 605.41 kB 605.41 kB = 107.22 kB 107.22 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 6.69 kB 6.69 kB = 1.83 kB 1.83 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js = 664.38 kB 664.38 kB = 117.09 kB 117.09 kB
facebook-www/ReactDOM-prod.classic.js = 688.25 kB 688.25 kB = 121.13 kB 121.13 kB
facebook-www/ReactDOM-prod.modern.js = 678.67 kB 678.67 kB = 119.49 kB 119.48 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-server-dom-esm/cjs/react-server-dom-esm-server.node.development.js +0.21% 211.58 kB 212.03 kB +0.13% 38.66 kB 38.71 kB
oss-stable/react-server-dom-esm/cjs/react-server-dom-esm-server.node.development.js +0.21% 211.58 kB 212.03 kB +0.13% 38.66 kB 38.71 kB
oss-experimental/react-server-dom-esm/cjs/react-server-dom-esm-server.node.development.js +0.21% 216.19 kB 216.64 kB +0.13% 39.48 kB 39.53 kB
oss-stable-semver/react-server-dom-parcel/cjs/react-server-dom-parcel-server.node.development.js +0.21% 218.09 kB 218.54 kB +0.13% 39.34 kB 39.39 kB
oss-stable/react-server-dom-parcel/cjs/react-server-dom-parcel-server.node.development.js +0.21% 218.09 kB 218.54 kB +0.13% 39.34 kB 39.39 kB
oss-experimental/react-server-dom-parcel/cjs/react-server-dom-parcel-server.node.development.js +0.20% 222.70 kB 223.15 kB +0.10% 40.17 kB 40.21 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.unbundled.development.js +0.20% 224.81 kB 225.26 kB +0.13% 40.41 kB 40.46 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.unbundled.development.js +0.20% 224.81 kB 225.26 kB +0.13% 40.41 kB 40.46 kB
facebook-react-native/react-test-renderer/cjs/ReactTestRenderer-prod.js = 344.56 kB 337.97 kB = 59.93 kB 58.76 kB
facebook-react-native/react-test-renderer/cjs/ReactTestRenderer-profiling.js = 369.36 kB 362.19 kB = 63.29 kB 62.13 kB
facebook-react-native/react-test-renderer/cjs/ReactTestRenderer-dev.js = 615.98 kB 603.76 kB = 98.61 kB 96.99 kB

Generated by 🚫 dangerJS against edf4dd5

@sebmarkbage sebmarkbage merged commit 0fa3250 into facebook:main Oct 28, 2025
246 checks passed
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