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: convert computed artifact loading to regular require() #6204

Merged
merged 7 commits into from
Oct 12, 2018
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
6 changes: 4 additions & 2 deletions lighthouse-core/audits/bootup-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const Audit = require('./audit');
const NetworkRequest = require('../lib/network-request');
const {taskGroups} = require('../lib/task-groups');
const i18n = require('../lib/i18n/i18n.js');
const NetworkRecords = require('../gather/computed/network-records.js');
const MainThreadTasks = require('../gather/computed/main-thread-tasks.js');

const UIStrings = {
/** Title of a diagnostic audit that provides detail on the time spent executing javascript files during the load. This descriptive title is shown to users when the amount is acceptable and no user action is required. */
Expand Down Expand Up @@ -108,8 +110,8 @@ class BootupTime extends Audit {
const settings = context.settings || {};
const trace = artifacts.traces[BootupTime.DEFAULT_PASS];
const devtoolsLog = artifacts.devtoolsLogs[BootupTime.DEFAULT_PASS];
const networkRecords = await artifacts.requestNetworkRecords(devtoolsLog);
const tasks = await artifacts.requestMainThreadTasks(trace);
const networkRecords = await NetworkRecords.request(devtoolsLog, context);
const tasks = await MainThreadTasks.request(trace, context);
const multiplier = settings.throttlingMethod === 'simulate' ?
settings.throttling.cpuSlowdownMultiplier : 1;

Expand Down
10 changes: 6 additions & 4 deletions lighthouse-core/audits/byte-efficiency/byte-efficiency-audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ const Audit = require('../audit');
const linearInterpolation = require('../../lib/statistics').linearInterpolation;
const Interactive = require('../../gather/computed/metrics/lantern-interactive');
const i18n = require('../../lib/i18n/i18n.js');
const NetworkRecords = require('../../gather/computed/network-records.js');
const LoadSimulator = require('../../gather/computed/load-simulator.js');
const PageDependencyGraph = require('../../gather/computed/page-dependency-graph.js');

const str_ = i18n.createMessageInstanceIdFn(__filename, {});

Expand Down Expand Up @@ -99,13 +102,12 @@ class UnusedBytes extends Audit {
settings,
};

return artifacts
.requestNetworkRecords(devtoolsLog)
return NetworkRecords.request(devtoolsLog, context)
.then(networkRecords =>
Promise.all([
this.audit_(artifacts, networkRecords, context),
artifacts.requestPageDependencyGraph({trace, devtoolsLog}),
artifacts.requestLoadSimulator(simulatorOptions),
PageDependencyGraph.request({trace, devtoolsLog}, context),
LoadSimulator.request(simulatorOptions, context),
])
)
.then(([result, graph, simulator]) => this.createAuditProduct(result, graph, simulator));
Expand Down
6 changes: 4 additions & 2 deletions lighthouse-core/audits/byte-efficiency/offscreen-images.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const ByteEfficiencyAudit = require('./byte-efficiency-audit');
const Sentry = require('../../lib/sentry');
const URL = require('../../lib/url-shim');
const i18n = require('../../lib/i18n/i18n.js');
const Interactive = require('../../gather/computed/metrics/interactive.js');
const TraceOfTab = require('../../gather/computed/trace-of-tab.js');

const UIStrings = {
/** Imperative title of a Lighthouse audit that tells the user to defer loading offscreen images. Offscreen images are images located outside of the visible browser viewport. As they are unseen by the user and slow down page load, they should be loaded later, closer to when the user is going to see them. This is displayed in a list of audit titles that Lighthouse generates. */
Expand Down Expand Up @@ -200,7 +202,7 @@ class OffscreenImages extends ByteEfficiencyAudit {
const unfilteredResults = Array.from(resultsMap.values());
// get the interactive time or fallback to getting the end of trace time
try {
const interactive = await artifacts.requestInteractive({trace, devtoolsLog, settings});
const interactive = await Interactive.request({trace, devtoolsLog, settings}, context);

// use interactive to generate items
const lanternInteractive = /** @type {LH.Artifacts.LanternMetric} */ (interactive);
Expand All @@ -216,7 +218,7 @@ class OffscreenImages extends ByteEfficiencyAudit {
}
// use end of trace as a substitute for finding interactive time
items = OffscreenImages.filterObservedResults(unfilteredResults,
await artifacts.requestTraceOfTab(trace).then(tot => tot.timestamps.traceEnd));
await TraceOfTab.request(trace, context).then(tot => tot.timestamps.traceEnd));
}

/** @type {LH.Result.Audit.OpportunityDetails['headings']} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ const BaseNode = require('../../lib/dependency-graph/base-node');
const ByteEfficiencyAudit = require('./byte-efficiency-audit');
const UnusedCSS = require('./unused-css-rules');
const NetworkRequest = require('../../lib/network-request');
const TraceOfTab = require('../../gather/computed/trace-of-tab.js');
const LoadSimulator = require('../../gather/computed/load-simulator.js');
const FirstContentfulPaint = require('../../gather/computed/metrics/first-contentful-paint.js');

/** @typedef {import('../../lib/dependency-graph/simulator/simulator')} Simulator */
/** @typedef {import('../../lib/dependency-graph/base-node.js').Node} Node */
Expand Down Expand Up @@ -83,14 +86,14 @@ class RenderBlockingResources extends Audit {
const trace = artifacts.traces[Audit.DEFAULT_PASS];
const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
const simulatorData = {devtoolsLog, settings: context.settings};
const traceOfTab = await artifacts.requestTraceOfTab(trace);
const simulator = await artifacts.requestLoadSimulator(simulatorData);
const traceOfTab = await TraceOfTab.request(trace, context);
const simulator = await LoadSimulator.request(simulatorData, context);
const wastedCssBytes = await RenderBlockingResources.computeWastedCSSBytes(artifacts, context);

const metricSettings = {throttlingMethod: 'simulate'};
const metricComputationData = {trace, devtoolsLog, simulator, settings: metricSettings};
// @ts-ignore - TODO(bckenny): allow optional `throttling` settings
const fcpSimulation = await artifacts.requestFirstContentfulPaint(metricComputationData);
const fcpSimulation = await FirstContentfulPaint.request(metricComputationData, context);
const fcpTsInMs = traceOfTab.timestamps.firstContentfulPaint / 1000;

const nodesByUrl = getNodesAndTimingByUrl(fcpSimulation.optimisticEstimate.nodeTimings);
Expand Down
3 changes: 2 additions & 1 deletion lighthouse-core/audits/byte-efficiency/total-byte-weight.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

const ByteEfficiencyAudit = require('./byte-efficiency-audit');
const i18n = require('../../lib/i18n/i18n.js');
const NetworkRecords = require('../../gather/computed/network-records.js');

const UIStrings = {
/** Title of a diagnostic audit that provides detail on large network resources required during page load. 'Payloads' is roughly equivalent to 'resources'. This descriptive title is shown to users when the amount is acceptable and no user action is required. */
Expand Down Expand Up @@ -58,7 +59,7 @@ class TotalByteWeight extends ByteEfficiencyAudit {
*/
static async audit(artifacts, context) {
const devtoolsLog = artifacts.devtoolsLogs[ByteEfficiencyAudit.DEFAULT_PASS];
const records = await artifacts.requestNetworkRecords(devtoolsLog);
const records = await NetworkRecords.request(devtoolsLog, context);

let totalBytes = 0;
/** @type {Array<{url: string, totalBytes: number}>} */
Expand Down
6 changes: 3 additions & 3 deletions lighthouse-core/audits/byte-efficiency/unused-css-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,15 @@ class UnusedCSSRules extends ByteEfficiencyAudit {

/**
* @param {LH.Artifacts} artifacts
* @param {Array<LH.Artifacts.NetworkRequest>} networkRecords
* @return {Promise<ByteEfficiencyAudit.ByteEfficiencyProduct>}
*/
static audit_(artifacts) {
static audit_(artifacts, networkRecords) {
const styles = artifacts.CSSUsage.stylesheets;
const usage = artifacts.CSSUsage.rules;
const pageUrl = artifacts.URL.finalUrl;

const devtoolsLogs = artifacts.devtoolsLogs[ByteEfficiencyAudit.DEFAULT_PASS];
return artifacts.requestNetworkRecords(devtoolsLogs).then(networkRecords => {
return Promise.resolve(networkRecords).then(networkRecords => {
const indexedSheets = UnusedCSSRules.indexStylesheetsById(styles, networkRecords);
UnusedCSSRules.indexUsedRules(usage, indexedSheets);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const NetworkRequest = require('../../lib/network-request');
const URL = require('../../lib/url-shim');
const linearInterpolation = require('../../lib/statistics').linearInterpolation;
const i18n = require('../../lib/i18n/i18n.js');
const NetworkRecords = require('../../gather/computed/network-records.js');

const UIStrings = {
/** Title of a diagnostic audit that provides detail on the cache policy applies to the page's static assets. Cache refers to browser disk cache, which keeps old versions of network resources around for future use. This is displayed in a list of audit titles that Lighthouse generates. */
Expand Down Expand Up @@ -175,7 +176,7 @@ class CacheHeaders extends Audit {
*/
static audit(artifacts, context) {
const devtoolsLogs = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
return artifacts.requestNetworkRecords(devtoolsLogs).then(records => {
return NetworkRecords.request(devtoolsLogs, context).then(records => {
const results = [];
let queryStringCount = 0;
let totalWastedBytes = 0;
Expand Down
6 changes: 4 additions & 2 deletions lighthouse-core/audits/critical-request-chains.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

const Audit = require('./audit');
const i18n = require('../lib/i18n/i18n.js');
const ComputedChains = require('../gather/computed/critical-request-chains.js');

const UIStrings = {
/** Imperative title of a Lighthouse audit that tells the user to reduce the depth of critical network requests to enhance initial load of a page. Critical request chains are series of dependent network requests that are important for page rendering. For example, here's a 4-request-deep chain: The biglogo.jpg image is required, but is requested via the styles.css style code, which is requested by the initialize.js javascript, which is requested by the page's HTML. This is displayed in a list of audit titles that Lighthouse generates. */
Expand Down Expand Up @@ -158,12 +159,13 @@ class CriticalRequestChains extends Audit {
/**
* Audits the page to give a score for First Meaningful Paint.
* @param {LH.Artifacts} artifacts The artifacts from the gather phase.
* @param {LH.Audit.Context} context
* @return {Promise<LH.Audit.Product>}
*/
static audit(artifacts) {
static audit(artifacts, context) {
const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
const URL = artifacts.URL;
return artifacts.requestCriticalRequestChains({devtoolsLog, URL}).then(chains => {
return ComputedChains.request({devtoolsLog, URL}, context).then(chains => {
let chainCount = 0;
/**
* @param {LH.Audit.SimpleCriticalRequestNode} node
Expand Down
6 changes: 4 additions & 2 deletions lighthouse-core/audits/dobetterweb/uses-http2.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
const URL = require('../../lib/url-shim');
const Audit = require('../audit');
const Util = require('../../report/html/renderer/util.js');
const NetworkRecords = require('../../gather/computed/network-records.js');

class UsesHTTP2Audit extends Audit {
/**
Expand All @@ -32,11 +33,12 @@ class UsesHTTP2Audit extends Audit {

/**
* @param {LH.Artifacts} artifacts
* @param {LH.Audit.Context} context
* @return {Promise<LH.Audit.Product>}
*/
static audit(artifacts) {
static audit(artifacts, context) {
const devtoolsLogs = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
return artifacts.requestNetworkRecords(devtoolsLogs).then(networkRecords => {
return NetworkRecords.request(devtoolsLogs, context).then(networkRecords => {
const finalHost = new URL(artifacts.URL.finalUrl).host;

const seenURLs = new Set();
Expand Down
6 changes: 4 additions & 2 deletions lighthouse-core/audits/font-display.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const Audit = require('./audit');
const NetworkRequest = require('../lib/network-request');
const allowedFontFaceDisplays = ['block', 'fallback', 'optional', 'swap'];
const i18n = require('../lib/i18n/i18n.js');
const NetworkRecords = require('../gather/computed/network-records.js');

const UIStrings = {
/** Title of a diagnostic audit that provides detail on if all the text on a webpage was visible while the page was loading its webfonts. This descriptive title is shown to users when the amount is acceptable and no user action is required. */
Expand Down Expand Up @@ -39,9 +40,10 @@ class FontDisplay extends Audit {

/**
* @param {LH.Artifacts} artifacts
* @param {LH.Audit.Context} context
* @return {Promise<LH.Audit.Product>}
*/
static audit(artifacts) {
static audit(artifacts, context) {
const devtoolsLogs = artifacts.devtoolsLogs[this.DEFAULT_PASS];
const fontFaces = artifacts.Fonts;

Expand All @@ -50,7 +52,7 @@ class FontDisplay extends Audit {
!fontFace.display || !allowedFontFaceDisplays.includes(fontFace.display)
);

return artifacts.requestNetworkRecords(devtoolsLogs).then((networkRecords) => {
return NetworkRecords.request(devtoolsLogs, context).then((networkRecords) => {
const results = networkRecords.filter(record => {
const isFont = record.resourceType === NetworkRequest.TYPES.Font;

Expand Down
6 changes: 4 additions & 2 deletions lighthouse-core/audits/is-on-https.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
const Audit = require('./audit');
const URL = require('../lib/url-shim');
const Util = require('../report/html/renderer/util');
const NetworkRecords = require('../gather/computed/network-records.js');

const SECURE_SCHEMES = ['data', 'https', 'wss', 'blob', 'chrome', 'chrome-extension', 'about'];
const SECURE_DOMAINS = ['localhost', '127.0.0.1'];
Expand Down Expand Up @@ -42,11 +43,12 @@ class HTTPS extends Audit {

/**
* @param {LH.Artifacts} artifacts
* @param {LH.Audit.Context} context
* @return {Promise<LH.Audit.Product>}
*/
static audit(artifacts) {
static audit(artifacts, context) {
const devtoolsLogs = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
return artifacts.requestNetworkRecords(devtoolsLogs).then(networkRecords => {
return NetworkRecords.request(devtoolsLogs, context).then(networkRecords => {
const insecureURLs = networkRecords
.filter(record => !HTTPS.isSecureRecord(record))
.map(record => URL.elideDataURI(record.url));
Expand Down
3 changes: 2 additions & 1 deletion lighthouse-core/audits/load-fast-enough-for-pwa.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
const isDeepEqual = require('lodash.isequal');
const Audit = require('./audit');
const mobileThrottling = require('../config/constants').throttling.mobileSlow4G;
const Interactive = require('../gather/computed/metrics/interactive.js');

// Maximum TTI to be considered "fast" for PWA baseline checklist
// https://developers.google.com/web/progressive-web-apps/checklist
Expand Down Expand Up @@ -54,7 +55,7 @@ class LoadFastEnough4Pwa extends Audit {
: Object.assign({}, context.settings, settingOverrides);

const metricComputationData = {trace, devtoolsLog, settings};
const tti = await artifacts.requestInteractive(metricComputationData);
const tti = await Interactive.request(metricComputationData, context);

const score = Number(tti.timing < MAXIMUM_TTI);

Expand Down
3 changes: 2 additions & 1 deletion lighthouse-core/audits/mainthread-work-breakdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
const Audit = require('./audit');
const {taskGroups} = require('../lib/task-groups');
const i18n = require('../lib/i18n/i18n.js');
const MainThreadTasks = require('../gather/computed/main-thread-tasks.js');

const UIStrings = {
/** Title of a diagnostic audit that provides detail on the main thread work the browser did to load the page. This descriptive title is shown to users when the amount is acceptable and no user action is required. */
Expand Down Expand Up @@ -81,7 +82,7 @@ class MainThreadWorkBreakdown extends Audit {
const settings = context.settings || {};
const trace = artifacts.traces[MainThreadWorkBreakdown.DEFAULT_PASS];

const tasks = await artifacts.requestMainThreadTasks(trace);
const tasks = await MainThreadTasks.request(trace, context);
const multiplier = settings.throttlingMethod === 'simulate' ?
settings.throttling.cpuSlowdownMultiplier : 1;

Expand Down
24 changes: 16 additions & 8 deletions lighthouse-core/audits/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
'use strict';

const Audit = require('./audit');
const TraceOfTab = require('../gather/computed/trace-of-tab.js');
const Speedline = require('../gather/computed/speedline.js');
const FirstContentfulPaint = require('../gather/computed/metrics/first-contentful-paint.js');
const FirstMeaningfulPaint = require('../gather/computed/metrics/first-meaningful-paint.js');
const FirstCPUIdle = require('../gather/computed/metrics/first-cpu-idle.js');
const Interactive = require('../gather/computed/metrics/interactive.js');
const SpeedIndex = require('../gather/computed/metrics/speed-index.js');
const EstimatedInputLatency = require('../gather/computed/metrics/estimated-input-latency.js');

class Metrics extends Audit {
/**
Expand All @@ -31,14 +39,14 @@ class Metrics extends Audit {
const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
const metricComputationData = {trace, devtoolsLog, settings: context.settings};

const traceOfTab = await artifacts.requestTraceOfTab(trace);
const speedline = await artifacts.requestSpeedline(trace);
const firstContentfulPaint = await artifacts.requestFirstContentfulPaint(metricComputationData);
const firstMeaningfulPaint = await artifacts.requestFirstMeaningfulPaint(metricComputationData);
const firstCPUIdle = await artifacts.requestFirstCPUIdle(metricComputationData);
const interactive = await artifacts.requestInteractive(metricComputationData);
const speedIndex = await artifacts.requestSpeedIndex(metricComputationData);
const estimatedInputLatency = await artifacts.requestEstimatedInputLatency(metricComputationData); // eslint-disable-line max-len
const traceOfTab = await TraceOfTab.request(trace, context);
const speedline = await Speedline.request(trace, context);
const firstContentfulPaint = await FirstContentfulPaint.request(metricComputationData, context);
const firstMeaningfulPaint = await FirstMeaningfulPaint.request(metricComputationData, context);
const firstCPUIdle = await FirstCPUIdle.request(metricComputationData, context);
const interactive = await Interactive.request(metricComputationData, context);
const speedIndex = await SpeedIndex.request(metricComputationData, context);
const estimatedInputLatency = await EstimatedInputLatency.request(metricComputationData, context); // eslint-disable-line max-len

/** @type {UberMetricsItem} */
const metrics = {
Expand Down
3 changes: 2 additions & 1 deletion lighthouse-core/audits/metrics/estimated-input-latency.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

const Audit = require('../audit');
const i18n = require('../../lib/i18n/i18n.js');
const ComputedEil = require('../../gather/computed/metrics/estimated-input-latency.js');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Eil 🤢


const UIStrings = {
/** The name of the metric that marks the estimated time between the page receiving input (a user clicking, tapping, or typing) and the page responding. Shown to users as the label for the numeric metric value. Ideally fits within a ~40 character limit. */
Expand Down Expand Up @@ -57,7 +58,7 @@ class EstimatedInputLatency extends Audit {
const trace = artifacts.traces[Audit.DEFAULT_PASS];
const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
const metricComputationData = {trace, devtoolsLog, settings: context.settings};
const metricResult = await artifacts.requestEstimatedInputLatency(metricComputationData);
const metricResult = await ComputedEil.request(metricComputationData, context);

return {
score: Audit.computeLogNormalScore(
Expand Down
3 changes: 2 additions & 1 deletion lighthouse-core/audits/metrics/first-contentful-paint.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

const Audit = require('../audit');
const i18n = require('../../lib/i18n/i18n.js');
const ComputedFcp = require('../../gather/computed/metrics/first-contentful-paint.js');

const UIStrings = {
/** The name of the metric that marks the time at which the first 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. */
Expand Down Expand Up @@ -54,7 +55,7 @@ class FirstContentfulPaint extends Audit {
const trace = artifacts.traces[Audit.DEFAULT_PASS];
const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
const metricComputationData = {trace, devtoolsLog, settings: context.settings};
const metricResult = await artifacts.requestFirstContentfulPaint(metricComputationData);
const metricResult = await ComputedFcp.request(metricComputationData, context);

return {
score: Audit.computeLogNormalScore(
Expand Down
Loading