Skip to content

Commit 95644fe

Browse files
Connor ClarkDevtools-frontend LUCI CQ
authored andcommitted
[RPP] Fix some bugs related to using the wrong time units
- The insights sorting criteria incorrectly used wrong time units for field data - #getFilmStripFrame incorrectly compared times in different units These bugs were discovered by a custom eslint rule that has not yet landed[1]. [1] https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6395588 Bug: 406518012 Change-Id: I7a19181bf1362f200bb9038dca6fff06b16555a3 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6417905 Auto-Submit: Connor Clark <[email protected]> Reviewed-by: Paul Irish <[email protected]> Commit-Queue: Connor Clark <[email protected]>
1 parent cf5c715 commit 95644fe

File tree

5 files changed

+20
-14
lines changed

5 files changed

+20
-14
lines changed

front_end/models/trace/Processor.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,20 +383,20 @@ describeWithEnvironment('TraceProcessor', function() {
383383
assert.deepEqual(orderWithoutMetadata, [
384384
'CLSCulprits',
385385
'Viewport',
386+
'Cache',
387+
'ImageDelivery',
386388
'InteractionToNextPaint',
387389
'LCPPhases',
388390
'LCPDiscovery',
389391
'RenderBlocking',
390392
'NetworkDependencyTree',
391-
'ImageDelivery',
392393
'DocumentLatency',
393394
'FontDisplay',
394395
'DOMSize',
395396
'ThirdParties',
396397
'DuplicatedJavaScript',
397398
'SlowCSSSelector',
398399
'ForcedReflow',
399-
'Cache',
400400
'ModernHTTP',
401401
'LegacyJavaScript',
402402
]);
@@ -406,20 +406,20 @@ describeWithEnvironment('TraceProcessor', function() {
406406
assert.deepEqual(orderWithMetadata, [
407407
'Viewport',
408408
'CLSCulprits',
409+
'Cache',
410+
'ImageDelivery',
409411
'InteractionToNextPaint',
410412
'LCPPhases',
411413
'LCPDiscovery',
412414
'RenderBlocking',
413415
'NetworkDependencyTree',
414-
'ImageDelivery',
415416
'DocumentLatency',
416417
'FontDisplay',
417418
'DOMSize',
418419
'ThirdParties',
419420
'DuplicatedJavaScript',
420421
'SlowCSSSelector',
421422
'ForcedReflow',
422-
'Cache',
423423
'ModernHTTP',
424424
'LegacyJavaScript',
425425
]);

front_end/models/trace/Processor.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,13 +381,15 @@ export class TraceProcessor extends EventTarget {
381381

382382
// Normalize the estimated savings to a single number, weighted by its relative impact
383383
// to the page experience based on the same scoring curve that Lighthouse uses.
384-
const observedLcp = Insights.Common.getLCP(insights, insightSet.id)?.value;
384+
const observedLcpMicro = Insights.Common.getLCP(insights, insightSet.id)?.value;
385+
const observedLcp = observedLcpMicro ? Helpers.Timing.microToMilli(observedLcpMicro) : Types.Timing.Milli(0);
385386
const observedCls = Insights.Common.getCLS(insights, insightSet.id).value;
386387

387388
// INP is special - if users did not interact with the page, we'll have no INP, but we should still
388389
// be able to prioritize insights based on this metric. When we observe no interaction, instead use
389390
// a default value for the baseline INP.
390-
const observedInp = Insights.Common.getINP(insights, insightSet.id)?.value ?? 200;
391+
const observedInpMicro = Insights.Common.getINP(insights, insightSet.id)?.value;
392+
const observedInp = observedInpMicro ? Helpers.Timing.microToMilli(observedInpMicro) : Types.Timing.Milli(200);
391393

392394
const observedLcpScore =
393395
observedLcp !== undefined ? Insights.Common.evaluateLCPMetricScore(observedLcp) : undefined;
@@ -400,8 +402,9 @@ export class TraceProcessor extends EventTarget {
400402
const inp = model.metricSavings?.INP ?? 0;
401403
const cls = model.metricSavings?.CLS ?? 0;
402404

403-
const lcpPostSavings = observedLcp !== undefined ? Math.max(0, observedLcp - lcp) : undefined;
404-
const inpPostSavings = Math.max(0, observedInp - inp);
405+
const lcpPostSavings =
406+
observedLcp !== undefined ? Math.max(0, observedLcp - lcp) as Types.Timing.Milli : undefined;
407+
const inpPostSavings = Math.max(0, observedInp - inp) as Types.Timing.Milli;
405408
const clsPostSavings = Math.max(0, observedCls - cls);
406409

407410
let score = 0;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ describeWithEnvironment('Common', function() {
5353
const {insightSet, metadata} = await process(this, 'image-delivery.json.gz');
5454

5555
const weights = calculateMetricWeightsForSorting(insightSet, metadata);
56-
assert.deepEqual(weights, {lcp: 0.48649783990559314, inp: 0.48649783990559314, cls: 0.027004320188813675});
56+
assert.deepEqual(weights, {lcp: 0.07778127820223579, inp: 0.5504200439526509, cls: 0.37179867784511333});
5757
});
5858
});
5959

front_end/models/trace/insights/Common.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ export function getCLS(
8484
return {value: maxScore, worstClusterEvent: worstCluster ?? null};
8585
}
8686

87-
export function evaluateLCPMetricScore(value: number): number {
87+
export function evaluateLCPMetricScore(value: Types.Timing.Milli): number {
8888
return getLogNormalScore({p10: 2500, median: 4000}, value);
8989
}
9090

91-
export function evaluateINPMetricScore(value: number): number {
91+
export function evaluateINPMetricScore(value: Types.Timing.Milli): number {
9292
return getLogNormalScore({p10: 200, median: 500}, value);
9393
}
9494

@@ -212,8 +212,8 @@ export function calculateMetricWeightsForSorting(
212212
const fieldLcp = fieldMetrics.lcp?.value ?? null;
213213
const fieldInp = fieldMetrics.inp?.value ?? null;
214214
const fieldCls = fieldMetrics.cls?.value ?? null;
215-
const fieldLcpScore = fieldLcp !== null ? evaluateLCPMetricScore(fieldLcp) : 0;
216-
const fieldInpScore = fieldInp !== null ? evaluateINPMetricScore(fieldInp) : 0;
215+
const fieldLcpScore = fieldLcp !== null ? evaluateLCPMetricScore(Helpers.Timing.microToMilli(fieldLcp)) : 0;
216+
const fieldInpScore = fieldInp !== null ? evaluateINPMetricScore(Helpers.Timing.microToMilli(fieldInp)) : 0;
217217
const fieldClsScore = fieldCls !== null ? evaluateCLSMetricScore(fieldCls) : 0;
218218
const fieldLcpScoreInverted = 1 - fieldLcpScore;
219219
const fieldInpScoreInverted = 1 - fieldInpScore;

front_end/panels/timeline/TimelineDetailsView.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,13 +405,16 @@ export class TimelineDetailsPane extends
405405
if (!this.#filmStrip) {
406406
return null;
407407
}
408+
408409
const screenshotTime = (frame.idle ? frame.startTime : frame.endTime);
409410
const filmStripFrame = Trace.Extras.FilmStrip.frameClosestToTimestamp(this.#filmStrip, screenshotTime);
410411
if (!filmStripFrame) {
411412
return null;
412413
}
414+
413415
const frameTimeMilliSeconds = Trace.Helpers.Timing.microToMilli(filmStripFrame.screenshotEvent.ts);
414-
return frameTimeMilliSeconds - frame.endTime < 10 ? filmStripFrame : null;
416+
const frameEndTimeMilliSeconds = Trace.Helpers.Timing.microToMilli(frame.endTime);
417+
return frameTimeMilliSeconds - frameEndTimeMilliSeconds < 10 ? filmStripFrame : null;
415418
}
416419

417420
#setSelectionForTimelineFrame(frame: Trace.Types.Events.LegacyTimelineFrame): void {

0 commit comments

Comments
 (0)