Skip to content

Commit 3d9d91d

Browse files
Connor ClarkDevtools-frontend LUCI CQ
authored andcommitted
[RPP] Show font name in FontDisplay insight
https://i.imgur.com/2xuPgZO.png Fixed: 369422196 Change-Id: If89a426a427e9521bd1c12ebd88b0b3899b02c7a Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6313665 Commit-Queue: Connor Clark <[email protected]> Reviewed-by: Paul Irish <[email protected]> Commit-Queue: Paul Irish <[email protected]> Auto-Submit: Connor Clark <[email protected]>
1 parent af6c2c2 commit 3d9d91d

File tree

7 files changed

+73
-29
lines changed

7 files changed

+73
-29
lines changed

front_end/models/trace/handlers/LayoutShiftsHandler.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,19 @@ interface LayoutShifts {
5353
renderFrameImplCreateChildFrameEvents: readonly Types.Events.RenderFrameImplCreateChildFrame[];
5454
domLoadingEvents: readonly Types.Events.DomLoading[];
5555
layoutImageUnsizedEvents: readonly Types.Events.LayoutImageUnsized[];
56-
beginRemoteFontLoadEvents: readonly Types.Events.BeginRemoteFontLoad[];
56+
remoteFonts: readonly RemoteFont[];
5757
scoreRecords: readonly ScoreRecord[];
5858
// TODO(crbug/41484172): should be readonly
5959
backendNodeIds: Protocol.DOM.BackendNodeId[];
6060
}
6161

62+
interface RemoteFont {
63+
display: string;
64+
url?: string;
65+
name?: string;
66+
beginRemoteFontLoadEvent: Types.Events.BeginRemoteFontLoad;
67+
}
68+
6269
// This represents the maximum #time we will allow a cluster to go before we
6370
// reset it.
6471
export const MAX_CLUSTER_DURATION = Helpers.Timing.milliToMicro(Types.Timing.Milli(5000));
@@ -84,7 +91,7 @@ const styleRecalcInvalidationEvents: Types.Events.StyleRecalcInvalidationTrackin
8491
const renderFrameImplCreateChildFrameEvents: Types.Events.RenderFrameImplCreateChildFrame[] = [];
8592
const domLoadingEvents: Types.Events.DomLoading[] = [];
8693
const layoutImageUnsizedEvents: Types.Events.LayoutImageUnsized[] = [];
87-
const beginRemoteFontLoadEvents: Types.Events.BeginRemoteFontLoad[] = [];
94+
const remoteFonts: RemoteFont[] = [];
8895

8996
const backendNodeIds = new Set<Protocol.DOM.BackendNodeId>();
9097

@@ -124,7 +131,7 @@ export function reset(): void {
124131
renderFrameImplCreateChildFrameEvents.length = 0;
125132
layoutImageUnsizedEvents.length = 0;
126133
domLoadingEvents.length = 0;
127-
beginRemoteFontLoadEvents.length = 0;
134+
remoteFonts.length = 0;
128135
backendNodeIds.clear();
129136
clusters.length = 0;
130137
sessionMaxScore = 0;
@@ -162,7 +169,18 @@ export function handleEvent(event: Types.Events.Event): void {
162169
layoutImageUnsizedEvents.push(event);
163170
}
164171
if (Types.Events.isBeginRemoteFontLoad(event)) {
165-
beginRemoteFontLoadEvents.push(event);
172+
remoteFonts.push({
173+
display: event.args.display,
174+
url: event.args.url,
175+
beginRemoteFontLoadEvent: event,
176+
});
177+
}
178+
if (Types.Events.isRemoteFontLoaded(event)) {
179+
for (const remoteFont of remoteFonts) {
180+
if (remoteFont.url === event.args.url) {
181+
remoteFont.name = event.args.name;
182+
}
183+
}
166184
}
167185
if (Types.Events.isPaintImage(event)) {
168186
paintImageEvents.push(event);
@@ -259,7 +277,7 @@ export async function finalize(): Promise<void> {
259277
renderFrameImplCreateChildFrameEvents.sort((a, b) => a.ts - b.ts);
260278
domLoadingEvents.sort((a, b) => a.ts - b.ts);
261279
layoutImageUnsizedEvents.sort((a, b) => a.ts - b.ts);
262-
beginRemoteFontLoadEvents.sort((a, b) => a.ts - b.ts);
280+
remoteFonts.sort((a, b) => a.beginRemoteFontLoadEvent.ts - b.beginRemoteFontLoadEvent.ts);
263281
paintImageEvents.sort((a, b) => a.ts - b.ts);
264282

265283
// Each function transforms the data used by the next, as such the invoke order
@@ -514,7 +532,7 @@ export function data(): LayoutShifts {
514532
renderFrameImplCreateChildFrameEvents,
515533
domLoadingEvents,
516534
layoutImageUnsizedEvents,
517-
beginRemoteFontLoadEvents,
535+
remoteFonts,
518536
scoreRecords,
519537
// TODO(crbug/41484172): change the type so no need to clone
520538
backendNodeIds: [...backendNodeIds],

front_end/models/trace/insights/FontDisplay.test.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import {describeWithEnvironment} from '../../../testing/EnvironmentHelpers.js';
66
import {getFirstOrError, getInsightOrError, processTrace} from '../../../testing/InsightHelpers.js';
7+
import type * as Types from '../types/types.js';
78

89
describeWithEnvironment('FontDisplay', function() {
910
it('finds no requests for remote fonts', async () => {
@@ -23,34 +24,40 @@ describeWithEnvironment('FontDisplay', function() {
2324

2425
assert.deepEqual(insight.fonts.map(f => ({...f, request: f.request.args.data.url})), [
2526
{
27+
name: undefined,
2628
request: 'https://fonts.gstatic.com/s/ptsans/v17/jizaRExUiTo99u79D0KExcOPIDU.woff2',
2729
display: 'auto',
28-
wastedTime: 20,
30+
wastedTime: 20 as Types.Timing.Milli,
2931
},
3032
{
33+
name: undefined,
3134
request: 'https://fonts.gstatic.com/s/droidsans/v18/SlGVmQWMvZQIdix7AFxXkHNSbRYXags.woff2',
3235
display: 'auto',
33-
wastedTime: 15,
36+
wastedTime: 15 as Types.Timing.Milli,
3437
},
3538
{
39+
name: undefined,
3640
request: 'https://fonts.gstatic.com/s/ptsans/v17/jizfRExUiTo99u79B_mh0O6tLR8a8zI.woff2',
3741
display: 'auto',
38-
wastedTime: 15,
42+
wastedTime: 15 as Types.Timing.Milli,
3943
},
4044
{
45+
name: undefined,
4146
request: 'https://fonts.gstatic.com/s/droidsans/v18/SlGWmQWMvZQIdix7AFxXmMh3eDs1ZyHKpWg.woff2',
4247
display: 'auto',
43-
wastedTime: 15,
48+
wastedTime: 15 as Types.Timing.Milli,
4449
},
4550
{
51+
name: undefined,
4652
request: 'https://fonts.gstatic.com/s/ptserif/v18/EJRVQgYoZZY2vCFuvAFWzr-_dSb_.woff2',
4753
display: 'auto',
48-
wastedTime: 15,
54+
wastedTime: 15 as Types.Timing.Milli,
4955
},
5056
{
57+
name: undefined,
5158
request: 'https://fonts.gstatic.com/s/lato/v24/S6u9w4BMUTPHh6UVSwiPGQ3q5d0.woff2',
5259
display: 'auto',
53-
wastedTime: 10,
60+
wastedTime: 10 as Types.Timing.Milli,
5461
},
5562
]);
5663
});

front_end/models/trace/insights/FontDisplay.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,15 @@ export function deps(): ['Meta', 'NetworkRequests', 'LayoutShifts'] {
3737
return ['Meta', 'NetworkRequests', 'LayoutShifts'];
3838
}
3939

40+
interface RemoteFont {
41+
name?: string;
42+
request: Types.Events.SyntheticNetworkRequest;
43+
display: string;
44+
wastedTime: Types.Timing.Milli;
45+
}
46+
4047
export type FontDisplayInsightModel = InsightModel<typeof UIStrings, {
41-
fonts: Array<{
42-
request: Types.Events.SyntheticNetworkRequest,
43-
display: string,
44-
wastedTime: Types.Timing.Milli,
45-
}>,
48+
fonts: RemoteFont[],
4649
}>;
4750

4851
function finalize(partialModel: PartialInsightModel<FontDisplayInsightModel>): FontDisplayInsightModel {
@@ -59,8 +62,9 @@ function finalize(partialModel: PartialInsightModel<FontDisplayInsightModel>): F
5962

6063
export function generateInsight(
6164
parsedTrace: RequiredData<typeof deps>, context: InsightSetContext): FontDisplayInsightModel {
62-
const fonts = [];
63-
for (const event of parsedTrace.LayoutShifts.beginRemoteFontLoadEvents) {
65+
const fonts: RemoteFont[] = [];
66+
for (const remoteFont of parsedTrace.LayoutShifts.remoteFonts) {
67+
const event = remoteFont.beginRemoteFontLoadEvent;
6468
if (!Helpers.Timing.eventIsInBounds(event, context.bounds)) {
6569
continue;
6670
}
@@ -71,10 +75,9 @@ export function generateInsight(
7175
continue;
7276
}
7377

74-
const display = event.args.display;
7578
let wastedTime = Types.Timing.Milli(0);
7679

77-
if (/^(block|fallback|auto)$/.test(display)) {
80+
if (/^(block|fallback|auto)$/.test(remoteFont.display)) {
7881
const wastedTimeMicro = Types.Timing.Micro(
7982
request.args.data.syntheticData.finishTime - request.args.data.syntheticData.sendStartTime);
8083
// TODO(crbug.com/352244504): should really end at the time of the next Commit trace event.
@@ -85,8 +88,9 @@ export function generateInsight(
8588
}
8689

8790
fonts.push({
91+
name: remoteFont.name,
8892
request,
89-
display,
93+
display: remoteFont.display,
9094
wastedTime,
9195
});
9296
}

front_end/models/trace/types/TraceEvents.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,6 +1377,15 @@ export interface BeginRemoteFontLoad extends UserTiming {
13771377
args: Args&{
13781378
display: string,
13791379
id: number,
1380+
url?: string,
1381+
};
1382+
}
1383+
1384+
export interface RemoteFontLoaded extends UserTiming {
1385+
name: Name.REMOTE_FONT_LOADED;
1386+
args: Args&{
1387+
url: string,
1388+
name: string,
13801389
};
13811390
}
13821391

@@ -2278,6 +2287,10 @@ export function isBeginRemoteFontLoad(event: Event): event is BeginRemoteFontLoa
22782287
return event.name === Name.BEGIN_REMOTE_FONT_LOAD;
22792288
}
22802289

2290+
export function isRemoteFontLoaded(event: Event): event is RemoteFontLoaded {
2291+
return event.name === Name.REMOTE_FONT_LOADED;
2292+
}
2293+
22812294
export function isPerformanceMeasure(event: Event): event is PerformanceMeasure {
22822295
return isUserTiming(event) && isPhaseAsync(event.ph);
22832296
}
@@ -3012,6 +3025,7 @@ export const enum Name {
30123025

30133026
DOM_LOADING = 'domLoading',
30143027
BEGIN_REMOTE_FONT_LOAD = 'BeginRemoteFontLoad',
3028+
REMOTE_FONT_LOADED = 'RemoteFontLoaded',
30153029

30163030
ANIMATION_FRAME = 'AnimationFrame',
30173031
ANIMATION_FRAME_PRESENTATION = 'AnimationFrame::Presentation',

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,13 @@ class EventRef extends HTMLElement {
6666

6767
type EventRefSupportedEvents = Trace.Types.Events.SyntheticNetworkRequest;
6868

69-
export function eventRef(event: EventRefSupportedEvents): Lit.TemplateResult {
70-
let title, text;
69+
export function eventRef(
70+
event: EventRefSupportedEvents, options?: {text?: string, title?: string}): Lit.TemplateResult {
71+
let title = options?.title;
72+
let text = options?.text;
7173
if (Trace.Types.Events.isSyntheticNetworkRequest(event)) {
72-
text = Utils.Helpers.shortenUrl(new URL(event.args.data.url));
73-
title = event.args.data.url;
74+
text = text ?? Utils.Helpers.shortenUrl(new URL(event.args.data.url));
75+
title = title ?? event.args.data.url;
7476
} else {
7577
Platform.TypeScriptUtilities.assertNever(
7678
event, `unsupported event in eventRef: ${(event as Trace.Types.Events.Event).name}`);

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ export class FontDisplay extends BaseInsightComponent<FontDisplayInsightModel> {
6060
headers: [i18nString(UIStrings.fontColumn), i18nString(UIStrings.wastedTimeColumn)],
6161
rows: this.model.fonts.map(font => ({
6262
values: [
63-
// TODO(crbug.com/369422196): the font name would be nicer here.
64-
eventRef(font.request),
63+
eventRef(font.request, {text: font.name}),
6564
i18n.TimeUtilities.millisToString(font.wastedTime),
6665
],
6766
overlays: [this.#overlayForRequest.get(font.request)],

front_end/testing/TraceHelpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ export function getBaseTraceParseModelData(overrides: Partial<ParsedTrace> = {})
612612
renderFrameImplCreateChildFrameEvents: [],
613613
domLoadingEvents: [],
614614
layoutImageUnsizedEvents: [],
615-
beginRemoteFontLoadEvents: [],
615+
remoteFonts: [],
616616
scoreRecords: [],
617617
backendNodeIds: [],
618618
paintImageEvents: [],

0 commit comments

Comments
 (0)