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

Add client performance markers and measurements #1534

Open
wants to merge 2 commits into
base: v1.x-2022-07
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/shy-feet-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/hydrogen': patch
---

Add client performance markers and measurements.
18 changes: 17 additions & 1 deletion packages/hydrogen/src/entry-client.tsx
Original file line number Diff line number Diff line change
@@ -231,7 +231,15 @@ function useServerResponse(state: any) {

if (rscReader) {
// The flight response was inlined during SSR, use it directly.
response = createFromReadableStream(rscReader);
const [streamForRsc, streamForMetrics] = rscReader.tee();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wish there was a better way to know when the stream is finished without tee-ing it.

Copy link
Contributor

@frandiox frandiox Jun 13, 2022

Choose a reason for hiding this comment

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

We are the ones creating this rscReader in this same file so we could just add a hook there, no? It's basically the same as DOMContentLoaded.

However, I don't think any of this is measuring the work that React does internally in createFromReadableStream since it's async and there are no hooks for that. We could add one and ask the React team to consider the use case, e.g. response.onDone = () => {}. I guess I'm not sure what part we're trying to measure here.

response = createFromReadableStream(streamForRsc);

const rscReaderForMetrics = streamForMetrics.getReader();
rscReaderForMetrics.read().then(function read({done}) {
if (done) performance.mark('--hydrogen-hydration-done');
else rscReaderForMetrics.read().then(read);
});

rscReader = null;
} else {
if (
@@ -246,10 +254,18 @@ function useServerResponse(state: any) {
window.BOOMR.plugins.Hydrogen.trackSubPageLoadPerformance();
}

performance.mark('--hydrogen-rsc-start');

// Request a new flight response.
response = createFromFetch(
fetch(`${RSC_PATHNAME}?state=` + encodeURIComponent(key))
);
performance.mark('--hydrogen-rsc-end');
Comment on lines +257 to +263
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, this all happens synchronously so I don't think there's a difference between rsc-start and rsc-end here, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like you are right. I had assumed that createFromFetch throw'ed.

performance.measure(
'--hydrogen-rsc-time',
'--hydrogen-rsc-start',
'--hydrogen-rsc-end'
);
}

cache.clear();
29 changes: 2 additions & 27 deletions yarn.lock
Original file line number Diff line number Diff line change
@@ -2508,31 +2508,6 @@
"@shopify/cli-kit" "2.0.14"
"@shopify/plugin-ngrok" "^0.2.4"

"@shopify/hydrogen@latest":
version "0.22.1"
resolved "https://registry.yarnpkg.com/@shopify/hydrogen/-/hydrogen-0.22.1.tgz#9d395fdec652b98f739aefa3af4aed3102e5fb23"
integrity sha512-MmUbC4reRX2grCDabXea4DgBsk8p5lGR5Y7nUyzW+CYYzJgm30gHiE6RLMqFjWX1IEllOMTBBfI0sm7Mea80tg==
dependencies:
"@vitejs/plugin-react" "^1.3.0"
abort-controller "^3.0.0"
body-parser "^1.20.0"
connect "^3.7.0"
es-module-lexer "^0.10.0"
fast-glob "^3.2.11"
graphql "^16.3.0"
graphql-tag "^2.12.6"
history "^5.3.0"
kolorist "^1.5.1"
magic-string "^0.26.1"
node-fetch "^2.6.7"
path-to-regexp "^6.2.0"
react-error-boundary "^3.1.3"
react-helmet-async "^1.2.3"
uuid "^8.3.2"
vite-plugin-inspect "^0.3.6"
web-streams-polyfill "^3.2.0"
worktop "^0.7.3"

"@shopify/mini-oxygen@^0.0.5":
version "0.0.5"
resolved "https://registry.yarnpkg.com/@shopify/mini-oxygen/-/mini-oxygen-0.0.5.tgz#bb34f07c6aeaf0c346c41e79ac97e811eb2630fc"
@@ -12097,7 +12072,7 @@ rc@^1.2.7, rc@^1.2.8:
minimist "^1.2.0"
strip-json-comments "~2.0.1"

react-dom@18.1.0, react-dom@^18.1.0:
react-dom@^18.1.0:
version "18.1.0"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-18.1.0.tgz#7f6dd84b706408adde05e1df575b3a024d7e8a2f"
integrity sha512-fU1Txz7Budmvamp7bshe4Zi32d0ll7ect+ccxNu9FlObT605GOEB8BfO4tmRJ39R5Zj831VCpvQ05QPBW5yb+w==
@@ -12177,7 +12152,7 @@ react-use@^17.4.0:
ts-easing "^0.2.0"
tslib "^2.1.0"

react@18.1.0, react@^18.1.0:
react@^18.1.0:
version "18.1.0"
resolved "https://registry.yarnpkg.com/react/-/react-18.1.0.tgz#6f8620382decb17fdc5cc223a115e2adbf104890"
integrity sha512-4oL8ivCz5ZEPyclFQXaNksK3adutVS8l2xzZU0cqEFrE9Sb7fC0EFK5uEk74wIreL1DERyjvsU915j1pcT2uEQ==