Skip to content

Commit

Permalink
add flag to FMP to indicate if it fell back to FMP candidate (#2851)
Browse files Browse the repository at this point in the history
  • Loading branch information
brendankenny authored and paulirish committed Aug 5, 2017
1 parent a829811 commit 46d9ba7
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lighthouse-core/audits/first-meaningful-paint.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ class FirstMeaningfulPaint extends Audit {
fMP: traceOfTab.timings.firstMeaningfulPaint,
onLoad: traceOfTab.timings.onLoad,
endOfTrace: traceOfTab.timings.traceEnd,
}
},
fmpFellBack: traceOfTab.fmpFellBack
};

Object.keys(extendedInfo.timings).forEach(key => {
Expand Down
1 change: 1 addition & 0 deletions lighthouse-core/closure/typedefs/ComputedArtifacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ let TraceTimes;
firstContentfulPaintEvt: TraceEvent,
firstMeaningfulPaintEvt: TraceEvent,
onLoadEvt: TraceEvent,
fmpFellBack: boolean,
}} */
let TraceOfTabArtifact;

Expand Down
3 changes: 3 additions & 0 deletions lighthouse-core/gather/computed/trace-of-tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@ class TraceOfTab extends ComputedArtifact {
let firstMeaningfulPaint = frameEvents.find(
e => e.name === 'firstMeaningfulPaint' && e.ts > navigationStart.ts
);
let fmpFellBack = false;

// If there was no firstMeaningfulPaint event found in the trace, the network idle detection
// may have not been triggered before Lighthouse finished tracing.
// In this case, we'll use the last firstMeaningfulPaintCandidate we can find.
// However, if no candidates were found (a bogus trace, likely), we fail.
if (!firstMeaningfulPaint) {
const fmpCand = 'firstMeaningfulPaintCandidate';
fmpFellBack = true;
log.verbose('trace-of-tab', `No firstMeaningfulPaint found, falling back to last ${fmpCand}`);
const lastCandidate = frameEvents.filter(e => e.name === fmpCand).pop();
if (!lastCandidate) {
Expand Down Expand Up @@ -131,6 +133,7 @@ class TraceOfTab extends ComputedArtifact {
firstContentfulPaintEvt: firstContentfulPaint,
firstMeaningfulPaintEvt: firstMeaningfulPaint,
onLoadEvt: onLoad,
fmpFellBack,
};
}
}
Expand Down
10 changes: 10 additions & 0 deletions lighthouse-core/test/audits/first-meaningful-paint-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ describe('Performance: first-meaningful-paint audit', () => {
it('scores the fMP correctly', () => {
assert.equal(fmpResult.score, 99);
});

it('did not fall back to an FMP candidate event', () => {
assert.ok(!fmpResult.extendedInfo.value.fmpFellBack);
});
});

describe('finds correct FMP', () => {
Expand All @@ -68,6 +72,7 @@ describe('Performance: first-meaningful-paint audit', () => {
assert.equal(result.rawValue, 529.9);
assert.equal(result.extendedInfo.value.timestamps.navStart, 29343540951);
assert.equal(result.extendedInfo.value.timings.fCP, 80.054);
assert.ok(!result.extendedInfo.value.fmpFellBack);
assert.ok(!result.debugString);
});
});
Expand All @@ -78,6 +83,7 @@ describe('Performance: first-meaningful-paint audit', () => {
assert.equal(result.rawValue, 632.4);
assert.equal(result.extendedInfo.value.timestamps.navStart, 8885424467);
assert.equal(result.extendedInfo.value.timings.fCP, 632.419);
assert.ok(!result.extendedInfo.value.fmpFellBack);
assert.ok(!result.debugString);
});
});
Expand All @@ -88,6 +94,7 @@ describe('Performance: first-meaningful-paint audit', () => {
assert.equal(result.rawValue, 878.4);
assert.equal(result.extendedInfo.value.timestamps.navStart, 1805796384607);
assert.equal(result.extendedInfo.value.timings.fCP, 879.046);
assert.ok(!result.extendedInfo.value.fmpFellBack);
assert.ok(!result.debugString);
});
});
Expand All @@ -97,6 +104,7 @@ describe('Performance: first-meaningful-paint audit', () => {
assert.equal(result.displayValue, '4,460\xa0ms');
assert.equal(result.rawValue, 4460.9);
assert.equal(result.extendedInfo.value.timings.fCP, 1494.73);
assert.ok(result.extendedInfo.value.fmpFellBack);
assert.ok(!result.debugString);
});
});
Expand All @@ -111,6 +119,8 @@ describe('Performance: first-meaningful-paint audit', () => {
assert.strictEqual(result.extendedInfo.value.timings.fMP, 482.318);
assert.strictEqual(result.extendedInfo.value.timestamps.fCP, undefined);
assert.strictEqual(result.extendedInfo.value.timestamps.fMP, 2149509604903);
// NOTE: falls back to candidate FMP
assert.ok(result.extendedInfo.value.fmpFellBack);
});
});
});
5 changes: 5 additions & 0 deletions lighthouse-core/test/gather/computed/trace-of-tab-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ describe('Trace of Tab computed artifact:', () => {
assert.equal(trace.navigationStartEvt.ts, 29343540951);
assert.equal(trace.firstContentfulPaintEvt.ts, 29343621005);
assert.equal(trace.firstMeaningfulPaintEvt.ts, 29344070867);
assert.ok(!trace.fmpFellBack);
});

it('if there was a tracingStartedInPage after the frame\'s navStart #2', () => {
Expand All @@ -66,6 +67,7 @@ describe('Trace of Tab computed artifact:', () => {
assert.equal(trace.navigationStartEvt.ts, 8885424467);
assert.equal(trace.firstContentfulPaintEvt.ts, 8886056886);
assert.equal(trace.firstMeaningfulPaintEvt.ts, 8886056891);
assert.ok(!trace.fmpFellBack);
});

it('if it appears slightly before the fCP', () => {
Expand All @@ -74,6 +76,7 @@ describe('Trace of Tab computed artifact:', () => {
assert.equal(trace.navigationStartEvt.ts, 1805796384607);
assert.equal(trace.firstContentfulPaintEvt.ts, 1805797263653);
assert.equal(trace.firstMeaningfulPaintEvt.ts, 1805797262960);
assert.ok(!trace.fmpFellBack);
});

it('from candidates if no defined FMP exists', () => {
Expand All @@ -82,6 +85,7 @@ describe('Trace of Tab computed artifact:', () => {
assert.equal(trace.navigationStartEvt.ts, 2146735807738);
assert.equal(trace.firstContentfulPaintEvt.ts, 2146737302468);
assert.equal(trace.firstMeaningfulPaintEvt.ts, 2146740268666);
assert.ok(trace.fmpFellBack);
});
});

Expand All @@ -91,6 +95,7 @@ describe('Trace of Tab computed artifact:', () => {
assert.equal(trace.navigationStartEvt.ts, 2149509122585, 'bad navStart');
assert.equal(trace.firstContentfulPaintEvt, undefined, 'bad fcp');
assert.equal(trace.firstMeaningfulPaintEvt.ts, 2149509604903, 'bad fmp');
assert.ok(trace.fmpFellBack);
});

it('handles traces missing a paints (captured in background tab)', () => {
Expand Down

0 comments on commit 46d9ba7

Please sign in to comment.