Skip to content

Commit

Permalink
core(speed-index): only compute perceptual speed index (#3845)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhulce authored and paulirish committed Nov 17, 2017
1 parent 33b1574 commit a9780d6
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 18 deletions.
4 changes: 1 addition & 3 deletions lighthouse-core/audits/speed-index-metric.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class SpeedIndexMetric extends Audit {
throw new Error('Trace unable to find visual progress frames.');
}

if (speedline.speedIndex === 0) {
if (speedline.perceptualSpeedIndex === 0) {
throw new Error('Error in Speedline calculating Speed Index (speedIndex of 0).');
}

Expand Down Expand Up @@ -71,14 +71,12 @@ class SpeedIndexMetric extends Audit {
firstVisualChange: speedline.first,
visuallyReady: visuallyReadyInMs,
visuallyComplete: speedline.complete,
speedIndex: speedline.speedIndex,
perceptualSpeedIndex: speedline.perceptualSpeedIndex,
},
timestamps: {
firstVisualChange: (speedline.first + speedline.beginning) * 1000,
visuallyReady: (visuallyReadyInMs + speedline.beginning) * 1000,
visuallyComplete: (speedline.complete + speedline.beginning) * 1000,
speedIndex: (speedline.speedIndex + speedline.beginning) * 1000,
perceptualSpeedIndex: (speedline.perceptualSpeedIndex + speedline.beginning) * 1000,
},
frames: speedline.frames.map(frame => {
Expand Down
1 change: 1 addition & 0 deletions lighthouse-core/gather/computed/speedline.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Speedline extends ComputedArtifact {
return speedline(traceEvents, {
timeOrigin: navStart,
fastMode: true,
include: 'perceptualSpeedIndex',
});
});
}
Expand Down
23 changes: 19 additions & 4 deletions lighthouse-core/test/audits/speed-index-metric-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

const Audit = require('../../audits/speed-index-metric.js');
const assert = require('assert');
const pwaTrace = require('../fixtures/traces/progressive-app.json');
const Runner = require('../../runner.js');

const emptyTraceStub = {
traces: {
Expand All @@ -34,6 +36,21 @@ describe('Performance: speed-index-metric audit', () => {
};
}

it('works on a real trace', () => {
const artifacts = Object.assign(Runner.instantiateComputedArtifacts(), {
traces: {defaultPass: {traceEvents: pwaTrace}},
});

return Audit.audit(artifacts).then(result => {
assert.equal(result.score, 100);
assert.equal(result.rawValue, 609);
assert.equal(Math.round(result.extendedInfo.value.timings.firstVisualChange), 475);
assert.equal(Math.round(result.extendedInfo.value.timings.visuallyReady), 700);
assert.equal(Math.round(result.extendedInfo.value.timings.visuallyComplete), 1105);
assert.equal(Math.round(result.extendedInfo.value.timings.perceptualSpeedIndex), 609);
});
});

it('throws an error if no frames', () => {
const artifacts = mockArtifactsWithSpeedlineResult({frames: []});
return Audit.audit(artifacts).then(
Expand All @@ -44,7 +61,7 @@ describe('Performance: speed-index-metric audit', () => {
it('throws an error if speed index of 0', () => {
const SpeedlineResult = {
frames: [frame(), frame(), frame()],
speedIndex: 0,
perceptualSpeedIndex: 0,
};
const artifacts = mockArtifactsWithSpeedlineResult(SpeedlineResult);

Expand All @@ -53,12 +70,11 @@ describe('Performance: speed-index-metric audit', () => {
_ => assert.ok(true));
});

it('scores speed index of 831 as 100', () => {
it('scores speed index of 845 as 100', () => {
const SpeedlineResult = {
frames: [frame(), frame(), frame()],
first: 630,
complete: 930,
speedIndex: 831,
perceptualSpeedIndex: 845,
};
const artifacts = mockArtifactsWithSpeedlineResult(SpeedlineResult);
Expand All @@ -67,7 +83,6 @@ describe('Performance: speed-index-metric audit', () => {
assert.equal(response.rawValue, 845);
assert.equal(response.extendedInfo.value.timings.firstVisualChange, 630);
assert.equal(response.extendedInfo.value.timings.visuallyComplete, 930);
assert.equal(response.extendedInfo.value.timings.speedIndex, 831);
assert.equal(response.extendedInfo.value.timings.perceptualSpeedIndex, 845);
});
});
Expand Down
11 changes: 6 additions & 5 deletions lighthouse-core/test/gather/computed/speedline-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,17 @@ describe('Speedline gatherer', () => {
});
});

it('measures the pwa.rocks example with speed index of 577', () => {
it('measures the pwa.rocks example', () => {
return computedArtifacts.requestSpeedline({traceEvents: pwaTrace}).then(speedline => {
return assert.equal(Math.floor(speedline.speedIndex), 561);
assert.equal(speedline.speedIndex, undefined);
assert.equal(Math.floor(speedline.perceptualSpeedIndex), 609);
});
});

it('measures SI of 3 frame trace (blank @1s, content @2s, more content @3s)', () => {
return computedArtifacts.requestSpeedline(threeFrameTrace).then(speedline => {
assert.equal(Math.floor(speedline.speedIndex), 2040);
return assert.equal(Math.floor(speedline.perceptualSpeedIndex), 2030);
assert.equal(speedline.speedIndex, undefined);
assert.equal(Math.floor(speedline.perceptualSpeedIndex), 2030);
});
});

Expand All @@ -59,7 +60,7 @@ describe('Speedline gatherer', () => {
assert.ok(Date.now() - start < 50, 'Quick results come from the cache');
assert.equal(firstResult, speedline, 'Cache match matches');

return assert.equal(Math.floor(speedline.speedIndex), 561);
return assert.equal(Math.floor(speedline.perceptualSpeedIndex), 609);
});
});

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"raven": "^2.2.1",
"rimraf": "^2.6.1",
"semver": "^5.3.0",
"speedline": "1.2.0",
"speedline": "1.3.0",
"update-notifier": "^2.1.0",
"whatwg-url": "4.0.0",
"ws": "1.1.2",
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2715,7 +2715,7 @@ loose-envify@^1.0.0:
dependencies:
js-tokens "^1.0.1"

loud-rejection@^1.0.0, loud-rejection@^1.3.0:
loud-rejection@^1.0.0, loud-rejection@^1.6.0:
version "1.6.0"
resolved "https://registry.yarnpkg.com/loud-rejection/-/loud-rejection-1.6.0.tgz#5b46f80147edee578870f086d04821cf998e551f"
dependencies:
Expand Down Expand Up @@ -3694,14 +3694,14 @@ spdx-license-ids@^1.0.2:
version "1.2.2"
resolved "https://registry.yarnpkg.com/spdx-license-ids/-/spdx-license-ids-1.2.2.tgz#c9df7a3424594ade6bd11900d596696dc06bac57"

speedline@1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/speedline/-/speedline-1.2.0.tgz#f5828dcf8e9b96a9f6c1da8ab298538820c6668d"
speedline@1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/speedline/-/speedline-1.3.0.tgz#201c458ca7aba2ac847fe5860c1a92966aaed3a9"
dependencies:
babar "0.0.3"
image-ssim "^0.2.0"
jpeg-js "^0.1.2"
loud-rejection "^1.3.0"
loud-rejection "^1.6.0"
meow "^3.7.0"

split2@^2.0.0:
Expand Down

0 comments on commit a9780d6

Please sign in to comment.