Skip to content

Commit

Permalink
core(tsc): add explicit index signature in mainthread-work-breakdown (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
brendankenny authored Aug 20, 2018
1 parent 9d3285c commit 0203330
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
7 changes: 5 additions & 2 deletions lighthouse-core/audits/mainthread-work-breakdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const UIStrings = {

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

/** @typedef {import('../lib/task-groups.js').TaskGroupIds} TaskGroupIds */

class MainThreadWorkBreakdown extends Audit {
/**
* @return {LH.Audit.Meta}
Expand Down Expand Up @@ -56,10 +58,10 @@ class MainThreadWorkBreakdown extends Audit {

/**
* @param {LH.Artifacts.TaskNode[]} tasks
* @return {Map<string, number>}
* @return {Map<TaskGroupIds, number>}
*/
static getExecutionTimingsByGroup(tasks) {
/** @type {Map<string, number>} */
/** @type {Map<TaskGroupIds, number>} */
const result = new Map();

for (const task of tasks) {
Expand All @@ -86,6 +88,7 @@ class MainThreadWorkBreakdown extends Audit {
const executionTimings = MainThreadWorkBreakdown.getExecutionTimingsByGroup(tasks);

let totalExecutionTime = 0;
/** @type {Record<string, number>} */
const categoryTotals = {};
const results = Array.from(executionTimings).map(([groupId, rawDuration]) => {
const duration = rawDuration * multiplier;
Expand Down
22 changes: 12 additions & 10 deletions lighthouse-core/lib/task-groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
*/
'use strict';

/** @typedef {'parseHTML'|'styleLayout'|'paintCompositeRender'|'scriptParseCompile'|'scriptEvaluation'|'garbageCollection'|'other'} TaskGroupIds */

/**
* @typedef TaskGroup
* @property {string} id
* @property {TaskGroupIds} id
* @property {string} label
* @property {string[]} traceEventNames
*/
Expand All @@ -16,15 +18,16 @@
* Make sure the traceEventNames keep up with the ones in DevTools
* @see https://cs.chromium.org/chromium/src/third_party/blink/renderer/devtools/front_end/timeline_model/TimelineModel.js?type=cs&q=TimelineModel.TimelineModel.RecordType+%3D&g=0&l=1156
* @see https://cs.chromium.org/chromium/src/third_party/blink/renderer/devtools/front_end/timeline/TimelineUIUtils.js?type=cs&q=_initEventStyles+-f:out+f:devtools&sq=package:chromium&g=0&l=39
* @type {{[P in TaskGroupIds]: {id: P, label: string, traceEventNames: Array<string>}}}
*/
const taskGroups = {
parseHTML: {
id: '',
id: 'parseHTML',
label: 'Parse HTML & CSS',
traceEventNames: ['ParseHTML', 'ParseAuthorStyleSheet'],
},
styleLayout: {
id: '',
id: 'styleLayout',
label: 'Style & Layout',
traceEventNames: [
'ScheduleStyleRecalculation',
Expand All @@ -35,7 +38,7 @@ const taskGroups = {
],
},
paintCompositeRender: {
id: '',
id: 'paintCompositeRender',
label: 'Rendering',
traceEventNames: [
'Animation',
Expand All @@ -55,12 +58,12 @@ const taskGroups = {
],
},
scriptParseCompile: {
id: '',
id: 'scriptParseCompile',
label: 'Script Parsing & Compilation',
traceEventNames: ['v8.compile', 'v8.compileModule', 'v8.parseOnBackground'],
},
scriptEvaluation: {
id: '',
id: 'scriptEvaluation',
label: 'Script Evaluation',
traceEventNames: [
'EventDispatch',
Expand All @@ -75,7 +78,7 @@ const taskGroups = {
],
},
garbageCollection: {
id: '',
id: 'garbageCollection',
label: 'Garbage Collection',
traceEventNames: [
'GCEvent',
Expand All @@ -87,7 +90,7 @@ const taskGroups = {
],
},
other: {
id: '',
id: 'other',
label: 'Other',
traceEventNames: [
'MessageLoop::RunTask',
Expand All @@ -99,8 +102,7 @@ const taskGroups = {

/** @type {Object<string, TaskGroup>} */
const taskNameToGroup = {};
for (const [groupId, group] of Object.entries(taskGroups)) {
group.id = groupId;
for (const group of Object.values(taskGroups)) {
for (const traceEventName of group.traceEventNames) {
taskNameToGroup[traceEventName] = group;
}
Expand Down

0 comments on commit 0203330

Please sign in to comment.