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(navigation-runner): only run getArtifact phase once #15827

Merged
merged 2 commits into from
Feb 22, 2024

Conversation

adamraine
Copy link
Member

@connorjclark noticed that we are running the getArtifact phase of the DT log and trace twice during a normal navigation run:

image

The root cause is that we attempt to get a preview of the DevtoolsLog and Trace artifacts before running through the getArtifact phase properly. This doesn't actually cause any problems because the getArtifact implementation is idempotent in both cases. However this could theoretically cause problems if that were to change down the line.

This PR adds a separate path for the navigation runner to get it's preview of the DT log and trace so that making changes to getArtifact is safer.

@adamraine adamraine requested a review from a team as a code owner February 22, 2024 00:07
@adamraine adamraine requested review from connorjclark and removed request for a team February 22, 2024 00:07
Copy link

vercel bot commented Feb 22, 2024

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

Name Status Preview Comments Updated (UTC)
lighthouse ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 22, 2024 0:07am

for (const definition of phaseState.artifactDefinitions) {
const {instance} = definition.gatherer;
if (instance instanceof DevtoolsLog) {
devtoolsLog = instance.getDebugData();
Copy link
Member

Choose a reason for hiding this comment

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

but... why not just getArtifact() ? types?

Copy link
Member Author

@adamraine adamraine Feb 22, 2024

Choose a reason for hiding this comment

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

I want to separate the getArtifact logic from the getDebugInfo logic even if they happen to be the same. Right now when designing gatherers we assume that getArtifact is only run once at the end of gathering. If we were to just reuse getArtifact here, it would break that assumption.

It's really just defensive coding to prevent future regressions if the impl of dtlog/trace change.

@@ -110,32 +110,20 @@ async function _navigate(navigationContext) {
* @return {Promise<{devtoolsLog?: LH.DevtoolsLog, records?: Array<LH.Artifacts.NetworkRequest>, trace?: LH.Trace}>}
*/
async function _collectDebugData(navigationContext, phaseState) {
const devtoolsLogArtifactDefn = phaseState.artifactDefinitions.find(
Copy link
Member

Choose a reason for hiding this comment

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

oh boy this is a pleasant diff to witness :)

let devtoolsLog;
let trace;

for (const definition of phaseState.artifactDefinitions) {
Copy link
Collaborator

@connorjclark connorjclark Feb 22, 2024

Choose a reason for hiding this comment

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

Did this change from a .find to a loop for some reason, or just preference?

I guess it got rid of the filter and is cleaner, jw.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's cleaner and made the type narrowing easier.

Copy link
Collaborator

Choose a reason for hiding this comment

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

oh! you did this b/c need to narrow types to use getDebugData

@adamraine adamraine merged commit 8662fbe into main Feb 22, 2024
30 checks passed
@adamraine adamraine deleted the trace-dt-debug-data branch February 22, 2024 22:05
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.

4 participants