Skip to content

Add client performance markers and measurements#1534

Open
blittle wants to merge 2 commits intov1.x-2022-07from
bl-add-client-perf-markers
Open

Add client performance markers and measurements#1534
blittle wants to merge 2 commits intov1.x-2022-07from
bl-add-client-perf-markers

Conversation

@blittle
Copy link
Copy Markdown
Contributor

@blittle blittle commented Jun 10, 2022

Resolves: Shopify/hydrogen#1479

Before submitting the PR, please make sure you do the following:

  • Read the Contributing Guidelines
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123)
  • Update docs in this repository according to your change
  • Run yarn changeset add if this PR cause a version bump based on Keep a Changelog and adheres to Semantic Versioning

@blittle blittle force-pushed the bl-add-client-perf-markers branch from 9f8cf50 to 8db4969 Compare June 10, 2022 19:53
@blittle blittle requested a review from a team June 10, 2022 19:53
if (rscReader) {
// The flight response was inlined during SSR, use it directly.
response = createFromReadableStream(rscReader);
const [streamForRsc, streamForMetrics] = rscReader.tee();
Copy link
Copy Markdown
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
Copy Markdown
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.

Copy link
Copy Markdown
Contributor

@frandiox frandiox left a comment

Choose a reason for hiding this comment

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

Leaving a couple of comments here but I'm not sure if I understand the use-case.
Also, hydration vs rsc is kind of confusing to me. What do you think about using initial-hydration/ssr-hydration vs rsc/hydration

Comment on lines +257 to +263
performance.mark('--hydrogen-rsc-start');

// Request a new flight response.
response = createFromFetch(
fetch(`${RSC_PATHNAME}?state=` + encodeURIComponent(key))
);
performance.mark('--hydrogen-rsc-end');
Copy link
Copy Markdown
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
Copy Markdown
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.

if (rscReader) {
// The flight response was inlined during SSR, use it directly.
response = createFromReadableStream(rscReader);
const [streamForRsc, streamForMetrics] = rscReader.tee();
Copy link
Copy Markdown
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Performance.mark annotations

2 participants