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

Improve reliability of finding navStart #1895

Merged
merged 2 commits into from
Mar 24, 2017
Merged

Improve reliability of finding navStart #1895

merged 2 commits into from
Mar 24, 2017

Conversation

paulirish
Copy link
Member

Fixes #1253 (the "ts of undefined" bug)


// The first TracingStartedInPage in the trace is definitely our renderer thread of interest
// Beware: the tracingStartedInPage event can appear slightly after a navigationStart
const startedInPageEvt = keyEvents.find(e => e.name === 'TracingStartedInPage');
// Filter to just events matching the frame ID for sanity
const frameEvents = keyEvents.filter(e => e.args.frame === startedInPageEvt.args.data.page);

// Our navStart will be the last frame navigation in the trace
const navigationStart = frameEvents.filter(e => e.name === 'navigationStart').pop();
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we throw here if it's undefined so we get slightly more friendly error?

return e.pid === startedInPageEvt.pid;
}).sort((event0, event1) => event0.ts - event1.ts);
const processEvents = trace.traceEvents
.filter(e => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: inline


return {
processEvents,
startedInPageEvt: startedInPageEvt,
navigationStartEvt: navigationStart,
firstPaintEvt: firstPaint,
firstContentfulPaintEvt: firstContentfulPaint,
firstMeaningfulPaintEvt: firstMeaningfulPaint
firstMeaningfulPaintEvt: firstMeaningfulPaint,
Copy link
Collaborator

Choose a reason for hiding this comment

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

:D

Copy link
Member Author

Choose a reason for hiding this comment

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

I started using https://github.com/prettier/prettier on demand in this PR. I'm already in love.

Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

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

couple of things

// Our navStart will be the latest one before fP.
const navigationStart = frameEvents.filter(e =>
e.name === 'navigationStart' && e.ts < firstPaint.ts).pop();
const firstPaint = frameEvents.find(e => e.name === 'firstPaint' && e.ts > navigationStart.ts);
Copy link
Member

Choose a reason for hiding this comment

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

strict > and not >=?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah. if FP was at the same time, i would have BIG concerns about the trace and i'd need to debug it. because that's definitely not correct.

const firstContentfulPaint = frameEvents.find(e =>
e.name === 'firstContentfulPaint' && e.ts >= firstPaint.ts);
const firstContentfulPaint = frameEvents.find(
e => e.name === 'firstContentfulPaint' && e.ts > navigationStart.ts
Copy link
Member

Choose a reason for hiding this comment

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

any significance of dropping the e.ts >= firstPaint.ts and using relative to navigationStart instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

we were using FP as the reference event before. Honestly this line could been asking for > navStart rather than FP, but it was just all FP for consistency.

.filter(e => {
return e.pid === startedInPageEvt.pid;
})
.sort((event0, event1) => event0.ts - event1.ts);
Copy link
Member

Choose a reason for hiding this comment

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

this formatting change makes the diff hard to read :P no difference, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

correct

@@ -148,19 +138,19 @@ class Metrics {
* @param {{ts: number, id: string, name: string}} navStart
Copy link
Member

Choose a reason for hiding this comment

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

delete navStart from jsdoc

@paulirish
Copy link
Member Author

thanks! updated.

Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

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

LGTM

nice sleuthing and fix

@@ -37,64 +36,64 @@ class Metrics {
getTs: auditResults => {
const fmpExt = auditResults['first-meaningful-paint'].extendedInfo;
return fmpExt.value.timestamps.navStart;
}
},
Copy link
Member

Choose a reason for hiding this comment

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

this is going to get old :P does it do the whole file when you change anything in it and save?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yah the whole file. I can avoid this if we want tho. :)

@paulirish paulirish merged commit ca2600a into master Mar 24, 2017
@denar90
Copy link
Contributor

denar90 commented Mar 24, 2017

thx guys 👍

@imjul1an
Copy link

is this fix already released?

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.

None yet

5 participants