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-artifacts): fix cache and add perf timing #6619

Merged
merged 3 commits into from
Nov 21, 2018

Conversation

brendankenny
Copy link
Member

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 in computed-artifact-test.js proved it's worth and will prevent this from regressing again.

Good news: runs should speed up :)

const artifactPromise = /** @type {ReturnType<C['compute_']>} */
(computableArtifact.compute_(artifacts, context));
cache.set(artifacts, artifactPromise);

artifactPromise.then(() => log.timeEnd(status)).catch(() => log.timeEnd(status));
Copy link
Member Author

@brendankenny brendankenny Nov 20, 2018

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 {
Copy link
Member

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?

@brendankenny brendankenny merged commit d964d66 into master Nov 21, 2018
@brendankenny brendankenny deleted the computedcache branch November 21, 2018 00:02
@brendankenny
Copy link
Member Author

brendankenny commented Nov 21, 2018

Good news: runs should speed up :)

effect isn't huge huge, but it helps.

An -A run on some saved verge artifacts drops about 11%, from 2.65s to 2.35s (averaged over 7 runs each) on my machine.

@@ -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 () => {
Copy link
Collaborator

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",
Copy link
Collaborator

Choose a reason for hiding this comment

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

❤️

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.

3 participants