Skip to content

Commit 47bdf18

Browse files
Adam RaineDevtools-frontend LUCI CQ
authored andcommitted
[RPP] Add DOM size insight component to experimental insights
https://screenshot.googleplex.com/BmX2qvJFKCsgcLE Bug: 372897811 Change-Id: I42007408c57a806fde1d379c1fbd004fd123e273 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6090118 Commit-Queue: Adam Raine <[email protected]> Reviewed-by: Paul Irish <[email protected]> Reviewed-by: Connor Clark <[email protected]>
1 parent 629b0a1 commit 47bdf18

File tree

6 files changed

+70
-0
lines changed

6 files changed

+70
-0
lines changed

config/gni/devtools_grd_files.gni

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1846,6 +1846,7 @@ grd_files_debug_sources = [
18461846
"front_end/panels/timeline/components/ignoreListSetting.css.js",
18471847
"front_end/panels/timeline/components/insights/BaseInsightComponent.js",
18481848
"front_end/panels/timeline/components/insights/CLSCulprits.js",
1849+
"front_end/panels/timeline/components/insights/DOMSize.js",
18491850
"front_end/panels/timeline/components/insights/DocumentLatency.js",
18501851
"front_end/panels/timeline/components/insights/EventRef.js",
18511852
"front_end/panels/timeline/components/insights/FontDisplay.js",

front_end/panels/timeline/components/SidebarSingleInsightSet.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ describeWithEnvironment('SidebarSingleInsightSet', () => {
153153
'Render blocking requests',
154154
'Document request latency',
155155
'Optimize viewport for mobile',
156+
'Optimize DOM size',
156157
'CSS Selector costs',
157158
]);
158159

@@ -164,6 +165,7 @@ describeWithEnvironment('SidebarSingleInsightSet', () => {
164165
'Render blocking requests',
165166
'Document request latency',
166167
'Optimize viewport for mobile',
168+
'Optimize DOM size',
167169
'CSS Selector costs',
168170
]);
169171
});

front_end/panels/timeline/components/SidebarSingleInsightSet.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export interface SidebarSingleInsightSetData {
4747
* users. */
4848
const EXPERIMENTAL_INSIGHTS: ReadonlySet<string> = new Set([
4949
'FontDisplay',
50+
'DOMSize',
5051
]);
5152

5253
type InsightNameToComponentMapping =
@@ -59,6 +60,7 @@ type InsightNameToComponentMapping =
5960
*/
6061
const INSIGHT_NAME_TO_COMPONENT: InsightNameToComponentMapping = {
6162
CLSCulprits: Insights.CLSCulprits.CLSCulprits,
63+
DOMSize: Insights.DOMSize.DOMSize,
6264
DocumentLatency: Insights.DocumentLatency.DocumentLatency,
6365
FontDisplay: Insights.FontDisplay.FontDisplay,
6466
ImageDelivery: Insights.ImageDelivery.ImageDelivery,

front_end/panels/timeline/components/insights/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ devtools_module("insights") {
1818
sources = [
1919
"BaseInsightComponent.ts",
2020
"CLSCulprits.ts",
21+
"DOMSize.ts",
2122
"DocumentLatency.ts",
2223
"EventRef.ts",
2324
"FontDisplay.ts",
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright 2024 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import '../../../../ui/components/icon_button/icon_button.js';
6+
7+
import * as i18n from '../../../../core/i18n/i18n.js';
8+
import type {DOMSizeInsightModel} from '../../../../models/trace/insights/DOMSize.js';
9+
import * as LitHtml from '../../../../ui/lit-html/lit-html.js';
10+
import type * as Overlays from '../../overlays/overlays.js';
11+
12+
import {BaseInsightComponent} from './BaseInsightComponent.js';
13+
14+
const UIStrings = {
15+
/**
16+
* @description Text status indicating that browser operations to re-render the page were not impacted by the size of the DOM. "DOM" is an acronym and should not be translated.
17+
*/
18+
noLargeRenderTasks: 'No rendering tasks impacted by DOM size',
19+
};
20+
21+
const str_ = i18n.i18n.registerUIStrings('panels/timeline/components/insights/DOMSize.ts', UIStrings);
22+
const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
23+
24+
const {html} = LitHtml;
25+
26+
export class DOMSize extends BaseInsightComponent<DOMSizeInsightModel> {
27+
static override readonly litTagName = LitHtml.literal`devtools-performance-dom-size`;
28+
override internalName: string = 'dom-size';
29+
30+
override createOverlays(): Overlays.Overlays.TimelineOverlay[] {
31+
if (!this.model) {
32+
return [];
33+
}
34+
35+
const entries = [...this.model.largeStyleRecalcs, ...this.model.largeLayoutUpdates];
36+
return entries.map(entry => ({
37+
type: 'ENTRY_OUTLINE',
38+
entry,
39+
outlineReason: 'ERROR',
40+
}));
41+
}
42+
43+
override renderContent(): LitHtml.LitTemplate {
44+
if (!this.model) {
45+
return LitHtml.nothing;
46+
}
47+
48+
if (!this.model.largeStyleRecalcs.length && !this.model.largeLayoutUpdates.length) {
49+
return html`<div class="insight-section">${i18nString(UIStrings.noLargeRenderTasks)}</div>`;
50+
}
51+
52+
return LitHtml.nothing;
53+
}
54+
}
55+
56+
declare global {
57+
interface HTMLElementTagNameMap {
58+
'devtools-performance-dom-size': DOMSize;
59+
}
60+
}
61+
62+
customElements.define('devtools-performance-dom-size', DOMSize);

front_end/panels/timeline/components/insights/insights.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import * as BaseInsightComponent from './BaseInsightComponent.js';
66
import * as CLSCulprits from './CLSCulprits.js';
77
import * as DocumentLatency from './DocumentLatency.js';
8+
import * as DOMSize from './DOMSize.js';
89
import * as EventRef from './EventRef.js';
910
import * as FontDisplay from './FontDisplay.js';
1011
import * as Helpers from './Helpers.js';
@@ -25,6 +26,7 @@ export {
2526
BaseInsightComponent,
2627
CLSCulprits,
2728
DocumentLatency,
29+
DOMSize,
2830
EventRef,
2931
FontDisplay,
3032
Helpers,

0 commit comments

Comments
 (0)