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(computed-artifact): remove settings and options from context #12435

Merged
merged 6 commits into from
May 3, 2021

Conversation

adamraine
Copy link
Member

Splitting this out from #12427 because it touches a lot of files.

Previously, calculating a computed artifact in the gathering stage required us to add settings and options to the context to be compatible with LH.Audit.Context. This PR adds a new context with just computedCache that computed artifacts use.

Right now the new context is LH.Gatherer.ComputedContext. Changing that should be a pretty simple find and replace so I'm open to other suggestions on where it should go.

@adamraine adamraine requested a review from a team as a code owner May 3, 2021 18:30
@adamraine adamraine requested review from patrickhulce and removed request for a team May 3, 2021 18:30
@google-cla google-cla bot added the cla: yes label May 3, 2021
Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for splitting!

@@ -11,7 +11,7 @@ const log = require('lighthouse-logger');
/**
* Decorate computableArtifact with a caching `request()` method which will
* automatically call `computableArtifact.compute_()` under the hood.
* @template {{name: string, compute_(artifacts: unknown, context: LH.Audit.Context): Promise<unknown>}} C
* @template {{name: string, compute_(artifacts: unknown, context: LH.Gatherer.ComputedContext): Promise<unknown>}} C
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't know that it belongs in either Audit or Gatherer, maybe in Artifacts namespace?

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 Artifacts sounds better.

* @param {{URL: LH.Artifacts['URL'], devtoolsLog: LH.DevtoolsLog}} data
* @param {LH.Audit.Context} context
* @param {{URL: LH.Artifacts['URL'], devtoolsLog: LH.DevtoolsLog, settings: ImmutableObject<LH.Config.Settings>}} data
* @param {LH.Gatherer.ComputedContext} context
* @return {Promise<Record<LH.Budget.ResourceType,ResourceEntry>>}
*/
static async compute_(data, context) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

do you think this should just accept a budget at this point rather than all of settings?

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'm going to make this change.

Only problem I found was in the test file for computed/resource-summary.js. The tests expect the first arg to be a subset of artifacts. Making this change disrupts that naming convention.

@brendankenny
Copy link
Member

from basics:

@@ -6251,6 +6251,12 @@
         "duration": 100,
         "entryType": "measure"
       },
+      {
+        "startTime": 0,
+        "name": "lh:computed:MainResource",
+        "duration": 100,
+        "entryType": "measure"
+      },
       {
         "startTime": 0,
         "name": "lh:audit:timing-budget",

❌  FAIL. LHR has changed.

a good example where you think you're getting a cached computed artifact but you're not :)

In this case lh:computed:MainResource is usually like 0.1 ms because NetworkRecords is cached, but it's hard to even notice you've hit this path since tsc only does the structural check. I wonder how often we trigger this.

@@ -189,6 +190,10 @@ declare global {
}

module Artifacts {
export type ComputedContext = Immutable<{
Copy link
Member

Choose a reason for hiding this comment

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

Kind of a tangent for where this should live now, this is the kind of thing I think is a good argument for us moving away from global types (no one needs to reference this type except computed artifacts, which already need to import ComputedArtifact, so that's a good namespace for the type to live in), but typescript really needs to fix microsoft/TypeScript#41825 before that's a very ergonomic approach for us in general.

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.

LGTM2. Thanks for fixing this!

@adamraine
Copy link
Member Author

a good example where you think you're getting a cached computed artifact but you're not

Yeah, this was hard to find. There may be more instances of this that we don't cover in our tests because the artifacts are only requested once.

@adamraine adamraine merged commit 5bd16c2 into master May 3, 2021
@adamraine adamraine deleted the computed-context branch May 3, 2021 19:55
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