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

core(tracehouse): split timeOrigin determination out of computeTraceOfTab #11253

Merged
merged 9 commits into from
Oct 22, 2020

Conversation

patrickhulce
Copy link
Collaborator

@patrickhulce patrickhulce commented Aug 11, 2020

Summary
Another noop tracehouse change that will make it easier for fraggle rock and tracehouse consumers in the future is needed for FR work now. This PR splits apart the computeTraceOfTab method into a few components.

  • computeTimeOrigin, a way to choose how you want your time origin to be computed
  • computeKeyTimingsForFrame, the bulk of the previous trace of tab logic given a specific frame and time origin
  • computeTraceEnd, helper function to prevent that bug from sneaking into the two places we use it :)

It has one user-facing impact which is a minor bug fix to our traceEnd computation. Previously we did not consider the maximum ts + dur time so it changes by a few ms in some situations.

Related Issues/PRs
ref #8984 #10325 #9519

@patrickhulce patrickhulce requested a review from a team as a code owner August 11, 2020 23:04
@patrickhulce patrickhulce requested review from brendankenny and removed request for a team August 11, 2020 23:04
@connorjclark
Copy link
Collaborator

connorjclark commented Aug 11, 2020

fraggle rock and tracehouse

maybe we should start a glossary :)

tracehouse
fraggle rock
smokehouse
lightrider
gatherer
audit
lantern

etc...

Copy link
Collaborator

@connorjclark connorjclark left a comment

Choose a reason for hiding this comment

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

i only have nits

lighthouse-core/lib/tracehouse/trace-processor.js Outdated Show resolved Hide resolved
lighthouse-core/lib/tracehouse/trace-processor.js Outdated Show resolved Hide resolved
@patrickhulce
Copy link
Collaborator Author

🦗

🦗

🦗

@patrickhulce
Copy link
Collaborator Author

@adamraine would you mind taking a look at this? :)

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.

😬 😳

is needed for FR work now

How is firstResourceSendRequest going to be used in FR? It seems like it would have a number of possible issues for anything but a 'navigation'

lighthouse-core/lib/tracehouse/trace-processor.js Outdated Show resolved Hide resolved
lighthouse-core/lib/tracehouse/trace-processor.js Outdated Show resolved Hide resolved
@patrickhulce
Copy link
Collaborator Author

How is firstResourceSendRequest going to be used in FR?

It's not. This refactor to eliminate automatic selection of time origin based on navigation is required, i.e. "split timeOrigin determination out of computeTraceOfTab" ;)

Copy link
Member

@adamraine adamraine left a comment

Choose a reason for hiding this comment

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

LGTM

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.

some last questions but regardless of the answers this LGTM2 and is ready to land

});

// Ensure our traceEnd reflects all page activity.
const traceEnd = this.computeTraceEnd(trace.traceEvents, timeOriginEvt);
Copy link
Member

Choose a reason for hiding this comment

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

any reason not to just pass trace.traceEvents into computeKeyTimingsForFrame and do traceEnd for real in there?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As in pass both frameEvents and all trace events?

Primary reason I did not do that is it violates the veil of abstraction that computeKeyTimingsForFrame well, computes the key timings for a frame :)

If the double computation is problematic I'd prefer to modify the return type of computeKeyTimingsForFrame to omit traceEnd entirely as a proper fix. The duplication of all the types to avoid a double computation didn't seem to be worth the tradeoff in confusion initially since the trace end computation is cheap (~0.5ms/MB of trace). Prefer this approach?

Copy link
Member

Choose a reason for hiding this comment

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

If the double computation is problematic

It's not fatally problematic, no more so than breaking the veil :) And definitely not worried about the computation cost. I was just curious about your thinking on which was less confusing, passing in both sets of events or fake computing it and then doing it for real. Breaking the type down might be worse but it's possible it would be ok...e.g. with an inferred return type on computeKeyTimingsForFrame, maybe?

I'm also trying to be more literal in my review comments. I was 95% sure you had already considered this question so I was 95% really just asking, and 5% suggesting considering it and then just asking as a consideration follow up :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Breaking the type down might be worse but it's possible it would be ok...e.g. with an inferred return type on computeKeyTimingsForFrame, maybe?

I like it SG!

Copy link
Member

Choose a reason for hiding this comment

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

If the double computation is problematic I'd prefer to modify the return type of computeKeyTimingsForFrame to omit traceEnd entirely as a proper fix.

Just noticed FrameTimings is a new typedef, and yeah, this would be the proper fix and it would be great if it's a simple modification to the Omit, but I don't know if there's an easy way to do that one level deep, so don't worry about it if there's not.

@@ -19,6 +19,15 @@ class LHTraceProcessor extends TraceProcessor {
return new LHError(LHError.errors.NO_NAVSTART);
}

/**
* This isn't ever actually used, but might one day be.
Copy link
Member

Choose a reason for hiding this comment

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

lol if this is true (and there aren't concrete FR plans for it), why are we refactoring and adding 'firstResourceSendRequest'? Why not refactor but have 'lastNavigationStart' be the only option right now?

Copy link
Member

Choose a reason for hiding this comment

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

well, looking at the excellent comment on computeTimeOrigin, maybe the simpler thing is to change this to something more concrete like

Suggested change
* This isn't ever actually used, but might one day be.
* This isn't currently used, but will be when the time origin of trace processing is changed.
* @see {TraceProcessor.computeTimeOrigin}

(the @see doesn't actually work like for that yet, but will soon(!), though if the thing isn't imported, I don't know if you actually have to do something like @see {import('../../path/to/trace-processor.js').computeTimeOrigin} or what)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

why are we [...] adding 'firstResourceSendRequest'?

firstResourceSendRequest won't be used for FR, but will be used for the #8984 line of work that will continue amidst FR.

Why not refactor but have 'lastNavigationStart' be the only option right now?

That's another option but a motivating example to validate the split seemed worthwhile to pair with the refactor given its simplicity and test uninterestingness if there's only one option :)

maybe the simpler thing is to change this to something more concrete like

sg 👍

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.

ok, two real things, sorry :)

@@ -242,6 +242,11 @@ const ERRORS = {
message: UIStrings.badTraceRecording,
lhrRuntimeError: true,
},
NO_RESOURCE_SEND: {
Copy link
Member

Choose a reason for hiding this comment

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

NO_FIRST_RESOURCE? NO_FIRST_RESOURCE_SEND?

Copy link
Member

Choose a reason for hiding this comment

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

Does this need to be added to the proto, too, since it's a lhrRuntimeError? Again it's a bit premature, but we might easily forget to do it when the error is live.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Does this need to be added to the proto, too, since it's a lhrRuntimeError? Again it's a bit premature, but we might easily forget to do it when the error is live.

Yeah sg might as well do it now too.

re: NO_FIRST_RESOURCE_SEND, any particular reason you'd like to see the addition of FIRST? It seemed like unnecessarily specific information to add to me that might lead to narrower usage later. The only way there can be no first resource request is if there were none at all :)

Copy link
Member

Choose a reason for hiding this comment

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

re: NO_FIRST_RESOURCE_SEND, any particular reason you'd like to see the addition of FIRST? It seemed like unnecessarily specific information to add to me that might lead to narrower usage later. The only way there can be no first resource request is if there were none at all :)

it's just short and I was wondering if there's more context we can give it. That's a very good point, though :)

"Resource send" is kind of confusing as representing the request for a resource, though (ResourceSendRequest does make sense with the other trace event names next to it). Maybe NO_RESOURCE_REQUEST? A slight step away from the trace event name but slightly more understandable on its own.

I'll stop bikeshedding after this :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

NO_RESOURCE_REQUEST

sold :)

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.

still LGTM :)

});

// Ensure our traceEnd reflects all page activity.
const traceEnd = this.computeTraceEnd(trace.traceEvents, timeOriginEvt);
Copy link
Member

Choose a reason for hiding this comment

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

If the double computation is problematic I'd prefer to modify the return type of computeKeyTimingsForFrame to omit traceEnd entirely as a proper fix.

Just noticed FrameTimings is a new typedef, and yeah, this would be the proper fix and it would be great if it's a simple modification to the Omit, but I don't know if there's an easy way to do that one level deep, so don't worry about it if there's not.

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

Successfully merging this pull request may close these issues.

6 participants