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

[Flight] Log Server Component into Performance Track #31729

Merged
merged 4 commits into from
Dec 12, 2024

Conversation

sebmarkbage
Copy link
Collaborator

@sebmarkbage sebmarkbage commented Dec 11, 2024

Screenshot 2024-12-10 at 10 49 19 PM

This emits a tree view visualization of the timing information for each Server Component provided in the RSC payload.

The unique thing about this visualization is that the end time of each Server Component spans the end of the last child. Now what is conceptually a blocking child is kind of undefined in RSC. E.g. if you're not using a Promise on the client, or if it is wrapped in Suspense, is it really blocking the parent?

Here I reconstruct parent-child relationship by which chunks reference other chunks. A child can belong to more than one parent like when we dedupe the result of a Server Component.

Then I wait until the whole RSC payload has streamed in, and then I traverse the tree collecting the end time from children as I go and emit the performance.measure() calls on the way up.

There's more work for this visualization in follow ups but this is the basics. For example, since the Server Component time span includes async work it's possible for siblings to execute their span in parallel (Foo and Bar in the screenshot are parallel siblings). To deal with this we need to spawn parallel work into separate tracks. Each one can be deep due to large trees. This can makes this type of visualization unwieldy when you have a lot of parallelism. Therefore I also plan another flatter Timeline visualization in a follow up.

The trick here is computing the end time based on when the last child row
resolves.
That way we can extend the end time of a component who reuses another
existing chunk that was already measured.
@sebmarkbage sebmarkbage requested review from gnoff and eps1lon December 11, 2024 04:02
Copy link

vercel bot commented Dec 11, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-compiler-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 11, 2024 4:16am

@react-sizebot
Copy link

react-sizebot commented Dec 11, 2024

Comparing: 79ddf5b...0010cf8

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.82 kB 1.82 kB
oss-stable/react-dom/cjs/react-dom-client.production.js = 510.76 kB 510.76 kB = 91.41 kB 91.41 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 = 515.69 kB 515.69 kB = 92.12 kB 92.12 kB
facebook-www/ReactDOM-prod.classic.js = 595.61 kB 595.61 kB = 105.12 kB 105.12 kB
facebook-www/ReactDOM-prod.modern.js = 585.88 kB 585.88 kB = 103.55 kB 103.55 kB
oss-experimental/react-server-dom-esm/cjs/react-server-dom-esm-client.browser.development.js +3.25% 96.15 kB 99.28 kB +3.68% 18.30 kB 18.97 kB
oss-experimental/react-client/cjs/react-client-flight.development.js +3.20% 97.47 kB 100.60 kB +3.85% 18.00 kB 18.69 kB
oss-experimental/react-server-dom-turbopack/cjs/react-server-dom-turbopack-client.browser.development.js +3.18% 98.34 kB 101.46 kB +3.60% 18.68 kB 19.36 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.browser.development.js +3.16% 98.89 kB 102.02 kB +3.56% 18.82 kB 19.49 kB
oss-experimental/react-server-dom-esm/cjs/react-server-dom-esm-client.node.development.js +3.12% 100.25 kB 103.37 kB +3.57% 19.01 kB 19.69 kB
oss-experimental/react-server-dom-turbopack/cjs/react-server-dom-turbopack-client.node.development.js +3.04% 102.89 kB 106.01 kB +3.44% 19.48 kB 20.15 kB
oss-experimental/react-server-dom-turbopack/cjs/react-server-dom-turbopack-client.edge.development.js +2.98% 104.64 kB 107.76 kB +3.38% 19.80 kB 20.47 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.development.js +2.98% 104.73 kB 107.85 kB +3.38% 19.84 kB 20.51 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.development.js +2.96% 105.63 kB 108.76 kB +3.37% 19.75 kB 20.41 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.development.js +2.92% 106.96 kB 110.09 kB +3.32% 20.00 kB 20.67 kB
oss-experimental/react-server-dom-esm/esm/react-server-dom-esm-client.browser.development.js +2.74% 135.90 kB 139.63 kB +3.34% 31.58 kB 32.64 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-esm/cjs/react-server-dom-esm-client.browser.development.js +3.25% 96.15 kB 99.28 kB +3.68% 18.30 kB 18.97 kB
oss-experimental/react-client/cjs/react-client-flight.development.js +3.20% 97.47 kB 100.60 kB +3.85% 18.00 kB 18.69 kB
oss-experimental/react-server-dom-turbopack/cjs/react-server-dom-turbopack-client.browser.development.js +3.18% 98.34 kB 101.46 kB +3.60% 18.68 kB 19.36 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.browser.development.js +3.16% 98.89 kB 102.02 kB +3.56% 18.82 kB 19.49 kB
oss-experimental/react-server-dom-esm/cjs/react-server-dom-esm-client.node.development.js +3.12% 100.25 kB 103.37 kB +3.57% 19.01 kB 19.69 kB
oss-experimental/react-server-dom-turbopack/cjs/react-server-dom-turbopack-client.node.development.js +3.04% 102.89 kB 106.01 kB +3.44% 19.48 kB 20.15 kB
oss-experimental/react-server-dom-turbopack/cjs/react-server-dom-turbopack-client.edge.development.js +2.98% 104.64 kB 107.76 kB +3.38% 19.80 kB 20.47 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.development.js +2.98% 104.73 kB 107.85 kB +3.38% 19.84 kB 20.51 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.development.js +2.96% 105.63 kB 108.76 kB +3.37% 19.75 kB 20.41 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.development.js +2.92% 106.96 kB 110.09 kB +3.32% 20.00 kB 20.67 kB
oss-experimental/react-server-dom-esm/esm/react-server-dom-esm-client.browser.development.js +2.74% 135.90 kB 139.63 kB +3.34% 31.58 kB 32.64 kB
oss-experimental/react-markup/cjs/react-markup.react-server.development.js +0.61% 511.16 kB 514.28 kB +0.80% 91.88 kB 92.61 kB

Generated by 🚫 dangerJS against f468d08

Console values don't have initializing chunks so no parent.
@sebmarkbage sebmarkbage merged commit 6928bf2 into facebook:main Dec 12, 2024
184 checks passed
sebmarkbage added a commit that referenced this pull request Dec 16, 2024
Stacked on #31729

<img width="1436" alt="Screenshot 2024-12-11 at 3 36 41 PM"
src="https://github.com/user-attachments/assets/0a201913-0076-4bbf-be18-8f1df6c58313"
/>

The Server Components visualization is currently a tree flame graph
where parent spans the child. This makes it equivalent to the Client
Components visualization.

However, since Server Components can be async and therefore parallel, we
need to do something when two children are executed in parallel. This PR
bumps parallel children into a separate track and then within that track
if that child has more children it can grow within that track.

I currently just cut off more than 10 parallel tracks.

Synchronous Server Components are still in sequence but it's unlikely
because even a simple microtasky Async Component is still parallel.

<img width="959" alt="Screenshot 2024-12-11 at 4 31 17 PM"
src="https://github.com/user-attachments/assets/5ad6a7f8-7fa0-46dc-af51-78caf9849176"
/>

I think this is probably not a very useful visualization for Server
Components but we can try it out.

I'm also going to try a different visualization where parent-child
relationship is horizontal and parallel vertical instead, but it might
not be possible to make that line up in this tool. It makes it a little
harder to see how much different components (including their children)
impact the overall tree. If that's the only visualization it's also
confusing why it's different dimensions than the Client Component
version.
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