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(largest-contentful-paint): add new metric #9706

Merged
merged 54 commits into from
Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
ec75de3
first pass
connorjclark Sep 20, 2019
183b080
update
connorjclark Sep 20, 2019
03f8ab6
i18n
connorjclark Sep 20, 2019
52a8d28
typos
connorjclark Sep 20, 2019
4e2e688
metrics
connorjclark Sep 20, 2019
f1836a0
ts
connorjclark Sep 20, 2019
449c7c5
fix
connorjclark Sep 20, 2019
d821da7
Apply suggestions from code review
connorjclark Sep 20, 2019
9cc6b8c
todo
connorjclark Sep 20, 2019
211a90b
fix lcp
connorjclark Sep 20, 2019
ee9f34e
update sample trace
connorjclark Sep 20, 2019
24db2ed
tweaks
connorjclark Sep 20, 2019
308f0fe
fix metrics-test
connorjclark Sep 20, 2019
33fecc9
rename all those pwa trace requires
connorjclark Sep 20, 2019
2b87da0
just update all the metric snapshots
connorjclark Sep 20, 2019
c473bf5
undo tests
connorjclark Sep 23, 2019
26bb02a
m79 in metrics test
connorjclark Sep 23, 2019
b848a73
m60
connorjclark Sep 23, 2019
967d630
lcp metric trace test
connorjclark Sep 24, 2019
5b80688
Merge remote-tracking branch 'origin/master' into lcp
connorjclark Sep 27, 2019
9da66f9
pr
connorjclark Sep 27, 2019
49aa30a
Update lighthouse-core/lib/tracehouse/trace-processor.js
connorjclark Sep 27, 2019
a71ab04
Merge branch 'lcp' of github.com:GoogleChrome/lighthouse into lcp
connorjclark Sep 27, 2019
7fd52f4
Apply suggestions from code review
connorjclark Sep 30, 2019
f351590
update traces
connorjclark Oct 1, 2019
ff42528
minify trace
connorjclark Oct 1, 2019
5e158e0
space raceeeeeeee
connorjclark Oct 1, 2019
c2c34e2
add broke test
connorjclark Oct 1, 2019
dbb1cde
invalidLcp for analyis
connorjclark Oct 1, 2019
59b34ae
simple trace test for lcp
connorjclark Oct 1, 2019
4cce545
create invalid lcp trace
connorjclark Oct 1, 2019
694ad7d
fix
connorjclark Oct 1, 2019
d74d208
delete stuff
connorjclark Oct 1, 2019
af84dd4
rm mistake
connorjclark Oct 1, 2019
b41c98f
rm candidateIndex
connorjclark Oct 1, 2019
328209d
test
connorjclark Oct 1, 2019
3173aff
update
connorjclark Oct 1, 2019
f713adc
trace of tab
connorjclark Oct 1, 2019
1424c68
trace of tab
connorjclark Oct 1, 2019
81fcec0
test
connorjclark Oct 1, 2019
9a8c269
push
connorjclark Oct 1, 2019
02843ab
lcpInvalidated
connorjclark Oct 1, 2019
697cf9b
typo
connorjclark Oct 1, 2019
2bb6b26
timings
connorjclark Oct 1, 2019
c80abb6
timestamps
connorjclark Oct 1, 2019
5fa41eb
nolcp
connorjclark Oct 1, 2019
ca65238
Update lighthouse-core/lib/tracehouse/trace-processor.js
connorjclark Oct 1, 2019
5fe7a48
more tests
connorjclark Oct 1, 2019
7c35c8b
Update lighthouse-core/lib/tracehouse/trace-processor.js
connorjclark Oct 1, 2019
9df0ea6
tst
connorjclark Oct 1, 2019
917f73a
Merge branch 'lcp' of github.com:GoogleChrome/lighthouse into lcp
connorjclark Oct 1, 2019
0c0dc97
Update lighthouse-core/audits/metrics.js
connorjclark Oct 1, 2019
6cc68e3
Update lighthouse-core/test/computed/metrics/largest-contentful-paint…
connorjclark Oct 1, 2019
793bfc6
sample
connorjclark Oct 2, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lighthouse-core/audits/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const TraceOfTab = require('../computed/trace-of-tab.js');
const Speedline = require('../computed/speedline.js');
const FirstContentfulPaint = require('../computed/metrics/first-contentful-paint.js');
const FirstMeaningfulPaint = require('../computed/metrics/first-meaningful-paint.js');
const LargestContentfulPaint = require('../computed/metrics/largest-contentful-paint.js');
brendankenny marked this conversation as resolved.
Show resolved Hide resolved
const FirstCPUIdle = require('../computed/metrics/first-cpu-idle.js');
const Interactive = require('../computed/metrics/interactive.js');
const SpeedIndex = require('../computed/metrics/speed-index.js');
Expand Down Expand Up @@ -40,7 +41,6 @@ class Metrics extends Audit {
const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
const metricComputationData = {trace, devtoolsLog, settings: context.settings};


/**
* @template TArtifacts
* @template TReturn
Expand All @@ -56,6 +56,7 @@ class Metrics extends Audit {
const speedline = await Speedline.request(trace, context);
const firstContentfulPaint = await FirstContentfulPaint.request(metricComputationData, context);
const firstMeaningfulPaint = await FirstMeaningfulPaint.request(metricComputationData, context);
const largestContentfulPaint = await LargestContentfulPaint.request(metricComputationData, context); // eslint-disable-line max-len
const firstCPUIdle = await requestOrUndefined(FirstCPUIdle, metricComputationData);
const interactive = await requestOrUndefined(Interactive, metricComputationData);
const speedIndex = await requestOrUndefined(SpeedIndex, metricComputationData);
Expand All @@ -69,6 +70,8 @@ class Metrics extends Audit {
firstContentfulPaintTs: firstContentfulPaint.timestamp,
firstMeaningfulPaint: firstMeaningfulPaint.timing,
firstMeaningfulPaintTs: firstMeaningfulPaint.timestamp,
largestContentfulPaint: largestContentfulPaint.timing,
largestContentfulPaintTs: largestContentfulPaint.timestamp,
firstCPUIdle: firstCPUIdle && firstCPUIdle.timing,
firstCPUIdleTs: firstCPUIdle && firstCPUIdle.timestamp,
interactive: interactive && interactive.timing,
Expand All @@ -88,6 +91,8 @@ class Metrics extends Audit {
observedFirstContentfulPaintTs: traceOfTab.timestamps.firstContentfulPaint,
observedFirstMeaningfulPaint: traceOfTab.timings.firstMeaningfulPaint,
observedFirstMeaningfulPaintTs: traceOfTab.timestamps.firstMeaningfulPaint,
observedLargestContentfulPaint: traceOfTab.timings.largestContentfulPaint,
brendankenny marked this conversation as resolved.
Show resolved Hide resolved
observedLargestContentfulPaintTs: traceOfTab.timestamps.largestContentfulPaint,
observedTraceEnd: traceOfTab.timings.traceEnd,
observedTraceEndTs: traceOfTab.timestamps.traceEnd,
observedLoad: traceOfTab.timings.load,
Expand Down Expand Up @@ -132,6 +137,8 @@ class Metrics extends Audit {
* @property {number=} firstContentfulPaintTs
* @property {number} firstMeaningfulPaint
* @property {number=} firstMeaningfulPaintTs
* @property {number} largestContentfulPaint
* @property {number=} largestContentfulPaintTs
* @property {number=} firstCPUIdle
* @property {number=} firstCPUIdleTs
* @property {number=} interactive
Expand All @@ -149,6 +156,8 @@ class Metrics extends Audit {
* @property {number} observedFirstContentfulPaintTs
* @property {number=} observedFirstMeaningfulPaint
* @property {number=} observedFirstMeaningfulPaintTs
* @property {number=} observedLargestContentfulPaint
* @property {number=} observedLargestContentfulPaintTs
* @property {number=} observedTraceEnd
* @property {number=} observedTraceEndTs
* @property {number=} observedLoad
Expand Down
73 changes: 73 additions & 0 deletions lighthouse-core/audits/metrics/largest-contentful-paint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
Copy link
Member

Choose a reason for hiding this comment

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

needs at least a sanity-check control flow test (see e.g. audits/metrics/fmp-test)

* @license Copyright 2019 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
'use strict';

const Audit = require('../audit.js');
const i18n = require('../../lib/i18n/i18n.js');
const ComputedLcp = require('../../computed/metrics/largest-contentful-paint.js');

const UIStrings = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

@connorjclark FYI this file is not necessary for HTTPArchive

/** The name of the metric that marks the time at which the largest text or image is painted by the browser. Shown to users as the label for the numeric metric value. Ideally fits within a ~40 character limit. */
title: 'Largest Contentful Paint',
/** Description of the Largest Contentful Paint (LCP) metric, which marks the time at which the largest text or image is painted by the browser. This is displayed within a tooltip when the user hovers on the metric name to see more. No character length limits. 'Learn More' becomes link text to additional documentation. */
description: 'Largest Contentful Paint marks the time at which the first text or image is ' +
connorjclark marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

can use https://web.dev/largest-contentful-paint for the link for now

It seems like the description is updated but the string itself is not? We shouldn't i18n the string if it isn't intended to be localized yet

`painted. [Learn more](https://developers.google.com/web/tools/lighthouse/audits/largest-contentful-paint).`,
};

const str_ = i18n.createMessageInstanceIdFn(__filename, UIStrings);

class LargestContentfulPaint extends Audit {
/**
* @return {LH.Audit.Meta}
*/
static get meta() {
return {
id: 'largest-contentful-paint',
title: str_(UIStrings.title),
description: str_(UIStrings.description),
scoreDisplayMode: Audit.SCORING_MODES.NUMERIC,
requiredArtifacts: ['traces', 'devtoolsLogs'],
};
}

/**
* @return {LH.Audit.ScoreOptions}
*/
static get defaultOptions() {
return {
// 75th and 95th percentiles HTTPArchive -> median and PODR
connorjclark marked this conversation as resolved.
Show resolved Hide resolved
// https://bigquery.cloud.google.com/table/httparchive:lighthouse.2018_04_01_mobile?pli=1
// see https://www.desmos.com/calculator/2t1ugwykrl
scorePODR: 2000,
scoreMedian: 4000,
};
}

/**
* @param {LH.Artifacts} artifacts
* @param {LH.Audit.Context} context
* @return {Promise<LH.Audit.Product>}
*/
static async audit(artifacts, context) {
const trace = artifacts.traces[Audit.DEFAULT_PASS];
const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
const metricComputationData = {trace, devtoolsLog, settings: context.settings};
const metricResult = await ComputedLcp.request(metricComputationData, context);

return {
score: Audit.computeLogNormalScore(
metricResult.timing,
context.options.scorePODR,
context.options.scoreMedian
),
numericValue: metricResult.timing,
displayValue: str_(i18n.UIStrings.seconds, {timeInMs: metricResult.timing}),
};
}
}

module.exports = LargestContentfulPaint;
module.exports.UIStrings = UIStrings;
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class LanternFirstMeaningfulPaint extends LanternMetric {
return LanternFirstContentfulPaint.getFirstPaintBasedGraph(
dependencyGraph,
fmp,
// See LanterFirstContentfulPaint's getOptimisticGraph implementation for a longer description
// See LanternFirstContentfulPaint's getOptimisticGraph implementation for a longer description
connorjclark marked this conversation as resolved.
Show resolved Hide resolved
// of why we exclude script initiated resources here.
node => node.hasRenderBlockingPriority() && node.initiatorType !== 'script'
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/**
* @license Copyright 2019 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
'use strict';

const makeComputedArtifact = require('../computed-artifact.js');
const LanternMetric = require('./lantern-metric.js');
const LHError = require('../../lib/lh-error.js');
const LanternFirstContentfulPaint = require('./lantern-first-contentful-paint.js');
Copy link
Collaborator

Choose a reason for hiding this comment

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

@connorjclark FYI this file is not necessary for HTTPArchive


/** @typedef {import('../../lib/dependency-graph/base-node.js').Node} Node */

class LanternLargestContentfulPaint extends LanternMetric {
/**
* @return {LH.Gatherer.Simulation.MetricCoefficients}
*/
static get COEFFICIENTS() {
return {
intercept: 0,
optimistic: 0.5,
pessimistic: 0.5,
};
}

/**
* TODO: Validate.
* @param {Node} dependencyGraph
* @param {LH.Artifacts.TraceOfTab} traceOfTab
* @return {Node}
*/
static getOptimisticGraph(dependencyGraph, traceOfTab) {
const lcp = traceOfTab.timestamps.largestContentfulPaint;
Copy link
Collaborator

Choose a reason for hiding this comment

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

so right now the impl is identical to FMP except we use the observed LCP for our moment of interest/cutoff? maybe a quick note of this in a fileoverview or for the methods here?

if LCP is as similar to FCP as FMP is this sounds great! if LCP is as different from FCP as I think it is then we'll probably need to get fancier. that'll all shake out in validation though :)

Copy link
Member

Choose a reason for hiding this comment

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

if LCP is as similar to FCP as FMP is this sounds great! if LCP is as different from FCP as I think it is then we'll probably need to get fancier. that'll all shake out in validation though :)

@patrickhulce how much do you suspect this? :)

If it's really different, there's not much benefit to landing a placeholder implementation (which needs tests, etc) instead of just returning the observed metric (or whatever) for now to keep the PR simpler.

Validation will really be local and having a stand-in impl on master doesn't help us much anyways, right?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would very surprised if we're able to continue with this approach.

there's not much benefit to landing a placeholder implementation (which needs tests, etc) instead of just returning the observed metric (or whatever) for now to keep the PR simpler.

That sounds like a reasonable way forward to me, though I'm not sure how much simpler it really gets given how light this part is :)

if (!lcp) {
throw new LHError(LHError.errors.NO_LCP);
}

return LanternFirstContentfulPaint.getFirstPaintBasedGraph(
connorjclark marked this conversation as resolved.
Show resolved Hide resolved
dependencyGraph,
lcp,
// See LanternFirstContentfulPaint's getOptimisticGraph implementation for a longer description
// of why we exclude script initiated resources here.
node => node.hasRenderBlockingPriority() && node.initiatorType !== 'script'
);
}

/**
* TODO: Validate.
* @param {Node} dependencyGraph
* @param {LH.Artifacts.TraceOfTab} traceOfTab
* @return {Node}
*/
static getPessimisticGraph(dependencyGraph, traceOfTab) {
const lcp = traceOfTab.timestamps.largestContentfulPaint;
if (!lcp) {
throw new LHError(LHError.errors.NO_LCP);
}

return LanternFirstContentfulPaint.getFirstPaintBasedGraph(
dependencyGraph,
lcp,
node => node.hasRenderBlockingPriority(),
// For pessimistic LCP we'll include *all* layout nodes
node => node.didPerformLayout()
);
}

/**
* @param {LH.Artifacts.MetricComputationDataInput} data
* @param {LH.Audit.Context} context
* @return {Promise<LH.Artifacts.LanternMetric>}
*/
static async compute_(data, context) {
const fcpResult = await LanternFirstContentfulPaint.request(data, context);
const metricResult = await this.computeMetricWithGraphs(data, context);
metricResult.timing = Math.max(metricResult.timing, fcpResult.timing);
return metricResult;
}
}

module.exports = makeComputedArtifact(LanternLargestContentfulPaint);
41 changes: 41 additions & 0 deletions lighthouse-core/computed/metrics/largest-contentful-paint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
connorjclark marked this conversation as resolved.
Show resolved Hide resolved
* @license Copyright 2019 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
'use strict';

const makeComputedArtifact = require('../computed-artifact.js');
const ComputedMetric = require('./metric.js');
const LHError = require('../../lib/lh-error.js');
const LanternLargestContentfulPaint = require('./lantern-largest-contentful-paint.js');

class LargestContentfulPaint extends ComputedMetric {
/**
* @param {LH.Artifacts.MetricComputationData} data
* @param {LH.Audit.Context} context
* @return {Promise<LH.Artifacts.LanternMetric>}
*/
static computeSimulatedMetric(data, context) {
return LanternLargestContentfulPaint.request(data, context);
}

/**
* @param {LH.Artifacts.MetricComputationData} data
* @return {Promise<LH.Artifacts.Metric>}
*/
static async computeObservedMetric(data) {
brendankenny marked this conversation as resolved.
Show resolved Hide resolved
const {traceOfTab} = data;
if (!traceOfTab.timestamps.largestContentfulPaint) {
throw new LHError(LHError.errors.NO_LCP);
}

return {
// LCP established as existing, so cast
timing: /** @type {number} */ (traceOfTab.timings.largestContentfulPaint),
timestamp: traceOfTab.timestamps.largestContentfulPaint,
};
}
}

module.exports = makeComputedArtifact(LargestContentfulPaint);
6 changes: 6 additions & 0 deletions lighthouse-core/lib/i18n/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,12 @@
"lighthouse-core/audits/metrics/interactive.js | title": {
"message": "Time to Interactive"
},
"lighthouse-core/audits/metrics/largest-contentful-paint.js | description": {
"message": "Largest Contentful Paint marks the time at which the first text or image is painted. [Learn more](https://developers.google.com/web/tools/lighthouse/audits/largest-contentful-paint)."
},
"lighthouse-core/audits/metrics/largest-contentful-paint.js | title": {
"message": "Largest Contentful Paint"
},
"lighthouse-core/audits/metrics/max-potential-fid.js | description": {
"message": "The maximum potential First Input Delay that your users could experience is the duration, in milliseconds, of the longest task. [Learn more](https://developers.google.com/web/updates/2018/05/first-input-delay)."
},
Expand Down
6 changes: 6 additions & 0 deletions lighthouse-core/lib/i18n/locales/en-XL.json
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,12 @@
"lighthouse-core/audits/metrics/interactive.js | title": {
"message": "T̂ím̂é t̂ó Îńt̂ér̂áĉt́îv́ê"
},
"lighthouse-core/audits/metrics/largest-contentful-paint.js | description": {
"message": "L̂ár̂ǵêśt̂ Ćôńt̂én̂t́f̂úl̂ Ṕâín̂t́ m̂ár̂ḱŝ t́ĥé t̂ím̂é ât́ ŵh́îćĥ t́ĥé f̂ír̂śt̂ t́êx́t̂ ór̂ ím̂áĝé îś p̂áîńt̂éd̂. [Ĺêár̂ń m̂ór̂é](https://developers.google.com/web/tools/lighthouse/audits/largest-contentful-paint)."
},
"lighthouse-core/audits/metrics/largest-contentful-paint.js | title": {
"message": "L̂ár̂ǵêśt̂ Ćôńt̂én̂t́f̂úl̂ Ṕâín̂t́"
},
"lighthouse-core/audits/metrics/max-potential-fid.js | description": {
"message": "T̂h́ê ḿâx́îḿûḿ p̂ót̂én̂t́îál̂ F́îŕŝt́ Îńp̂út̂ D́êĺâý t̂h́ât́ ŷóûŕ ûśêŕŝ ćôúl̂d́ êx́p̂ér̂íêńĉé îś t̂h́ê d́ûŕât́îón̂, ín̂ ḿîĺl̂íŝéĉón̂d́ŝ, óf̂ t́ĥé l̂ón̂ǵêśt̂ t́âśk̂. [Ĺêár̂ń m̂ór̂é](https://developers.google.com/web/updates/2018/05/first-input-delay)."
},
Expand Down
4 changes: 4 additions & 0 deletions lighthouse-core/lib/lh-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,10 @@ const ERRORS = {
code: 'NO_FMP',
message: UIStrings.badTraceRecording,
},
NO_LCP: {
code: 'NO_LCP',
message: UIStrings.badTraceRecording,
},

// TTI calculation failures
FMP_TOO_LATE_FOR_FCPUI: {code: 'FMP_TOO_LATE_FOR_FCPUI', message: UIStrings.pageLoadTookTooLong},
Expand Down
15 changes: 15 additions & 0 deletions lighthouse-core/lib/tracehouse/trace-processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,19 @@ class TraceProcessor {
firstMeaningfulPaint = lastCandidate;
}

// LCP comes from the latest `largestContentfulPaint::Candidate`, but it can be invalidated
// by a `largestContentfulPaint::Invalidate` event. In the case that the last candidate is
// invalidated, the value will be null.
connorjclark marked this conversation as resolved.
Show resolved Hide resolved
let largestContentfulPaint;
patrickhulce marked this conversation as resolved.
Show resolved Hide resolved
for (let i = frameEvents.length - 1; i >= 0; i--) {
const e = frameEvents[i];
if (e.ts <= navigationStart.ts) break;
if (e.name === 'largestContentfulPaint::Invalidate') break;
Copy link
Member

Choose a reason for hiding this comment

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

can we add a test for this case?

i'd like to base the test from a real trace.

Copy link
Collaborator

Choose a reason for hiding this comment

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

can we get a single comment above each if case space shuttle style? in my first read I missed that we were counting backwards and was very confused :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

+1 to test cases for these :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

hmmmm luckily i just made a huge corpus of new traces.

Copy link
Collaborator Author

@connorjclark connorjclark Sep 27, 2019

Choose a reason for hiding this comment

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

I ran it on a bunch of traces
(i also put a log at if (e.name === 'largestContentfulPaint::Invalidate')):

find dist/collect-lantern-traces -name '*trace.json' | xargs -I{} node -e "\
    const path = '{}'; \
    console.log(path); \
    const trace = JSON.parse(require('fs').readFileSync(path, 'utf-8')); \
    // wpt traces start with an empty event ...
    trace.traceEvents = trace.traceEvents.filter(e => Object.keys(e).length > 0); \
    const traceOfTab = require('./lighthouse-core/lib/tracehouse/trace-processor.js').computeTraceOfTab(trace); \
    console.log(traceOfTab.timings.largestContentfulPaint)";

and I never hit the log point.

In fact, only two of these collected traces have largestContentfulPaint::Invalidate.

  1. https---www-huffpost-com--mobile-unthrottled-4-trace.json - it's not from the main frame, so we ignore it.
  2. https---www-reddit-com--mobile-wpt-2-trace.json - after a short gap, it's followed by a largestContentfulPaint::Candidate.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

note that some basic test cases can also be constructed by e.g. create-test-trace.js (and then adding LCP events), or lack of LCP can be found with existing traces :) This should make testing at least some of this more lightweight.

It's obviously still good to find a real trace as you're doing to make sure the tests match what happens in reality (especially with cases like invalidation)

Copy link
Collaborator

Choose a reason for hiding this comment

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

IMO a real trace test for this does not need to be blocking landing (create-test-trace.js is nice :)), though if we wanted to add a flag that indicates if we fell into the invalidate path so we can examine frequency in HTTPArchive it wouldn't be the worst idea :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

would still love some of those space shuttle comments though :D

if (e.name !== 'largestContentfulPaint::Candidate') continue;
largestContentfulPaint = e;
break;
}

const load = frameEvents.find(e => e.name === 'loadEventEnd' && e.ts > navigationStart.ts);
const domContentLoaded = frameEvents.find(
e => e.name === 'domContentLoadedEventEnd' && e.ts > navigationStart.ts
Expand Down Expand Up @@ -551,6 +564,7 @@ class TraceProcessor {
firstPaint: getTimestamp(firstPaint),
firstContentfulPaint: getTimestamp(firstContentfulPaint),
firstMeaningfulPaint: getTimestamp(firstMeaningfulPaint),
largestContentfulPaint: getTimestamp(largestContentfulPaint),
traceEnd: fakeEndOfTraceEvt.ts,
load: getTimestamp(load),
domContentLoaded: getTimestamp(domContentLoaded),
Expand All @@ -566,6 +580,7 @@ class TraceProcessor {
firstPaint: maybeGetTiming(timestamps.firstPaint),
firstContentfulPaint: maybeGetTiming(timestamps.firstContentfulPaint),
firstMeaningfulPaint: maybeGetTiming(timestamps.firstMeaningfulPaint),
largestContentfulPaint: maybeGetTiming(timestamps.largestContentfulPaint),
traceEnd: getTiming(timestamps.traceEnd),
load: maybeGetTiming(timestamps.load),
domContentLoaded: maybeGetTiming(timestamps.domContentLoaded),
Expand Down
Loading