Skip to content

Commit 6d38e6c

Browse files
Adam RaineDevtools-frontend LUCI CQ
authored andcommitted
[ImageDeliver] Combine images into one list
https://screenshot.googleplex.com/5gkWCqJ5c9tTDzG Bug: 372897377 Change-Id: Id0ae9d67407be27a14e8a290809a9f6a0923d83a Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6072711 Reviewed-by: Paul Irish <[email protected]> Commit-Queue: Paul Irish <[email protected]>
1 parent 0b67d2d commit 6d38e6c

File tree

2 files changed

+31
-86
lines changed

2 files changed

+31
-86
lines changed

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

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ class ImageRef extends HTMLElement {
8484
readonly #boundRender = this.#render.bind(this);
8585

8686
#request?: Trace.Types.Events.SyntheticNetworkRequest;
87-
#imagePaint?: Trace.Types.Events.PaintImage;
8887

8988
connectedCallback(): void {
9089
this.#shadow.adoptedStyleSheets = [baseInsightComponentStyles];
@@ -95,11 +94,6 @@ class ImageRef extends HTMLElement {
9594
void ComponentHelpers.ScheduledRender.scheduleRender(this, this.#boundRender);
9695
}
9796

98-
set imagePaint(imagePaint: Trace.Types.Events.PaintImage|undefined) {
99-
this.#imagePaint = imagePaint;
100-
void ComponentHelpers.ScheduledRender.scheduleRender(this, this.#boundRender);
101-
}
102-
10397
#render(): void {
10498
if (!this.#request) {
10599
return;
@@ -117,9 +111,7 @@ class ImageRef extends HTMLElement {
117111
<span class="element-img-details">
118112
${eventRef(this.#request)}
119113
<span class="element-img-details-size">${
120-
this.#imagePaint ?
121-
`${this.#imagePaint.args.data.srcWidth}x${this.#imagePaint.args.data.srcHeight}` :
122-
i18n.ByteUtilities.bytesToString(this.#request.args.data.decodedBodyLength ?? 0)
114+
i18n.ByteUtilities.bytesToString(this.#request.args.data.decodedBodyLength ?? 0)
123115
}</span>
124116
</span>
125117
</div>
@@ -133,13 +125,10 @@ function handleBadImage(event: Event): void {
133125
img.style.display = 'none';
134126
}
135127

136-
export function imageRef(
137-
request: Trace.Types.Events.SyntheticNetworkRequest,
138-
imagePaint?: Trace.Types.Events.PaintImage): LitHtml.TemplateResult {
128+
export function imageRef(request: Trace.Types.Events.SyntheticNetworkRequest): LitHtml.TemplateResult {
139129
return html`
140130
<devtools-performance-image-ref
141131
.request=${request}
142-
.imagePaint=${imagePaint}
143132
></devtools-performance-image-ref>
144133
`;
145134
}

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

Lines changed: 29 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ import '../../../../ui/components/icon_button/icon_button.js';
66
import './Table.js';
77

88
import * as i18n from '../../../../core/i18n/i18n.js';
9-
import type {
10-
ImageDeliveryInsightModel, ImageOptimizationType, OptimizableImage} from
11-
'../../../../models/trace/insights/ImageDelivery.js';
12-
import * as Trace from '../../../../models/trace/trace.js';
9+
import type {ImageDeliveryInsightModel} from '../../../../models/trace/insights/ImageDelivery.js';
10+
import type * as Trace from '../../../../models/trace/trace.js';
1311
import * as LitHtml from '../../../../ui/lit-html/lit-html.js';
1412
import type * as Overlays from '../../overlays/overlays.js';
1513

@@ -20,10 +18,6 @@ import type {TableDataRow} from './Table.js';
2018
const {html} = LitHtml;
2119

2220
const UIStrings = {
23-
/**
24-
* @description Column header for a table column containing network requests for images that are not sized correctly for how they are displayed on the page.
25-
*/
26-
sizeAppropriately: 'Size appropriately',
2721
/**
2822
* @description Column header for a table column containing network requests for images which can improve their file size (e.g. use a different format, increase compression, etc).
2923
*/
@@ -38,6 +32,8 @@ const UIStrings = {
3832
const str_ = i18n.i18n.registerUIStrings('panels/timeline/components/insights/ImageDelivery.ts', UIStrings);
3933
const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
4034

35+
const MAX_REQUESTS = 6;
36+
4137
export class ImageDelivery extends BaseInsightComponent<ImageDeliveryInsightModel> {
4238
static override readonly litTagName = LitHtml.literal`devtools-performance-image-delivery`;
4339
override internalName: string = 'image-delivery';
@@ -59,88 +55,48 @@ export class ImageDelivery extends BaseInsightComponent<ImageDeliveryInsightMode
5955
};
6056
}
6157

62-
#getTopImagesAsRows(
63-
optimizableImages: OptimizableImage[], typeFilter: (type: ImageOptimizationType) => boolean,
64-
showDimensions?: boolean): TableDataRow[] {
65-
const MAX_REQUESTS = 3;
58+
override renderContent(): LitHtml.LitTemplate {
59+
if (!this.model) {
60+
return LitHtml.nothing;
61+
}
62+
63+
const optimizableImages = this.model.optimizableImages;
64+
6665
const topImages =
67-
optimizableImages.filter(image => image.optimizations.some(o => typeFilter(o.type)))
68-
.sort((a, b) => b.request.args.data.decodedBodyLength - a.request.args.data.decodedBodyLength);
66+
optimizableImages.sort((a, b) => b.request.args.data.decodedBodyLength - a.request.args.data.decodedBodyLength);
6967

7068
const remaining = topImages.splice(MAX_REQUESTS);
71-
7269
const rows: TableDataRow[] = topImages.map(image => ({
73-
values: [
74-
imageRef(
75-
image.request,
76-
showDimensions ? image.largestImagePaint : undefined,
77-
),
78-
],
70+
values: [imageRef(image.request)],
7971
overlays: [this.#createOverlayForRequest(image.request)],
8072
}));
8173

8274
if (remaining.length > 0) {
83-
const value = remaining.length > 1 ? i18nString(UIStrings.others, {PH1: remaining.length}) :
84-
imageRef(
85-
remaining[0].request,
86-
showDimensions ? remaining[0].largestImagePaint : undefined,
87-
);
75+
const value =
76+
remaining.length > 1 ? i18nString(UIStrings.others, {PH1: remaining.length}) : imageRef(remaining[0].request);
8877
rows.push({
8978
values: [value],
9079
overlays: remaining.map(r => this.#createOverlayForRequest(r.request)),
9180
});
9281
}
9382

94-
return rows;
95-
}
96-
97-
override renderContent(): LitHtml.LitTemplate {
98-
if (!this.model) {
83+
if (!rows.length) {
9984
return LitHtml.nothing;
10085
}
10186

102-
const optimizableImages = this.model.optimizableImages;
103-
104-
const sections = [];
105-
106-
const responsiveSizeRows = this.#getTopImagesAsRows(
107-
optimizableImages, type => type === Trace.Insights.Models.ImageDelivery.ImageOptimizationType.RESPONSIVE_SIZE,
108-
true);
109-
if (responsiveSizeRows.length) {
110-
// clang-format off
111-
sections.push(html`
112-
<div class="insight-section">
113-
<devtools-performance-table
114-
.data=${{
115-
insight: this,
116-
headers: [i18nString(UIStrings.sizeAppropriately)],
117-
rows: responsiveSizeRows,
118-
}}>
119-
</devtools-performance-table>
120-
</div>
121-
`);
122-
// clang-format on
123-
}
124-
125-
const optimizeFormatRows = this.#getTopImagesAsRows(
126-
optimizableImages, type => type !== Trace.Insights.Models.ImageDelivery.ImageOptimizationType.RESPONSIVE_SIZE);
127-
if (optimizeFormatRows.length) {
128-
// clang-format off
129-
sections.push(html`
130-
<div class="insight-section">
131-
<devtools-performance-table
132-
.data=${{
133-
insight: this,
134-
headers: [i18nString(UIStrings.optimizeFile)],
135-
rows: optimizeFormatRows,
136-
}}>
137-
</devtools-performance-table>
138-
</div>
139-
`);
140-
// clang-format on
141-
}
142-
143-
return html`${sections}`;
87+
// clang-format off
88+
return html`
89+
<div class="insight-section">
90+
<devtools-performance-table
91+
.data=${{
92+
insight: this,
93+
headers: [i18nString(UIStrings.optimizeFile)],
94+
rows,
95+
}}>
96+
</devtools-performance-table>
97+
</div>
98+
`;
99+
// clang-format on
144100
}
145101
}
146102

0 commit comments

Comments
 (0)