-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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-artifacts): fix cache and add perf timing #6619
Conversation
const artifactPromise = /** @type {ReturnType<C['compute_']>} */ | ||
(computableArtifact.compute_(artifacts, context)); | ||
cache.set(artifacts, artifactPromise); | ||
|
||
artifactPromise.then(() => log.timeEnd(status)).catch(() => log.timeEnd(status)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is unfortunate until we have Promise.finally
:) (standard in Node 10)
Otherwise if there's a error thrown in the computed artifact this branch is considered an unhandled rejection and we try to kill Lighthouse early.
@@ -12,7 +12,7 @@ const assert = require('assert'); | |||
const makeComputedArtifact = require('../../computed/computed-artifact.js'); | |||
|
|||
describe('ComputedArtifact base class', () => { | |||
it.skip('caches computed artifacts by strict equality', async () => { | |||
it('caches computed artifacts by strict equality', async () => { | |||
let computeCounter = 0; | |||
|
|||
const TestComputedArtifact = makeComputedArtifact(class TestComputedArtifact { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class as expression hurts my head, especially since it has the same name as something different
can you extract?
effect isn't huge huge, but it helps. An |
@@ -12,19 +12,19 @@ const assert = require('assert'); | |||
const makeComputedArtifact = require('../../computed/computed-artifact.js'); | |||
|
|||
describe('ComputedArtifact base class', () => { | |||
it.skip('caches computed artifacts by strict equality', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh I see now :)
@@ -3474,6 +3474,12 @@ | |||
"duration": 100, | |||
"entryType": "measure" | |||
}, | |||
{ | |||
"startTime": 0, | |||
"name": "lh:computed:NetworkRecords", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
split off from #6618
log timing was added at the same time that core: convert computed artifact loading to regular require() #6204 updated computed artifacts, so timing info hasn't actually been collected for computed artifacts (timing was still accounted for in the audits that called them, though). This PR adds timing to the new version.
core: convert computed artifact loading to regular require() #6204 messed up and was using strict equality testing for the computed artifact cache, not deep equality. Computed artifacts that take a bare artifact (e.g.
trace-of-tab
) had no issue with this and cached correctly. Any computed artifact that take a more complicated input (e.g. all the metrics) always found keys to be unequal, and so reran their computations every time they were called. This was especially bad in the lantern metrics, which tend to call each other a lot and benefit a good deal from caching.This PR defaults
ArbitraryEqualityMap
to using deep equality now (since that's the only way we use it), and the kind of goofball test updated incomputed-artifact-test.js
proved it's worth and will prevent this from regressing again.Good news: runs should speed up :)