Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚀 Report cls-fcp and cls-ofv to compare with cls #33207

Merged
merged 4 commits into from
Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/enums.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export const TickLabel = {
CONTENT_LAYOUT_DELAY: 'cld',
CUMULATIVE_LAYOUT_SHIFT: 'cls',
CUMULATIVE_LAYOUT_SHIFT_2: 'cls-2',
// TODO(#33207): Remove after data collection
CUMULATIVE_LAYOUT_SHIFT_BEFORE_FCP: 'cls-fcp',
CUMULATIVE_LAYOUT_SHIFT_BEFORE_VISIBLE: 'cls-ofv',
DOCUMENT_READY: 'dr',
END_INSTALL_STYLES: 'e_is',
FIRST_CONTENTFUL_PAINT: 'fcp',
Expand Down
12 changes: 12 additions & 0 deletions src/service/performance-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ export class Performance {

this.ampdoc_.whenFirstVisible().then(() => {
this.tick(TickLabel.ON_FIRST_VISIBLE);
// TODO(#33207): Remove after data collection
this.tick(
TickLabel.CUMULATIVE_LAYOUT_SHIFT_BEFORE_VISIBLE,
this.aggregateShiftScore_
);
this.flush();
});

Expand Down Expand Up @@ -350,6 +355,13 @@ export class Performance {
this.tickDelta(TickLabel.FIRST_CONTENTFUL_PAINT, value);
this.tickSinceVisible(TickLabel.FIRST_CONTENTFUL_PAINT_VISIBLE, value);
recordedFirstContentfulPaint = true;

// TODO(#33207): remove after data collection
// On the first contentful paint, report cumulative CLS score
this.tickDelta(
TickLabel.CUMULATIVE_LAYOUT_SHIFT_BEFORE_FCP,
this.aggregateShiftScore_
);
} else if (
entry.entryType === 'first-input' &&
!recordedFirstInputDelay
Expand Down
22 changes: 16 additions & 6 deletions test/unit/test-performance.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ describes.realWin('performance', {amp: true}, (env) => {
]).then(() => {
expect(flushSpy).to.have.callCount(4);
expect(perf.isMessagingReady_).to.be.false;
const count = 5;
const count = 6;
expect(perf.events_.length).to.equal(count);
});
});
Expand Down Expand Up @@ -653,13 +653,15 @@ describes.realWin('performance', {amp: true}, (env) => {
const initialCount = tickSpy.callCount;
return ampdoc.whenFirstVisible().then(() => {
clock.tick(400);
expect(tickSpy).to.have.callCount(initialCount + 1);
// TODO(#33207): reduce call counts by 1 after data collection
expect(tickSpy).to.have.callCount(initialCount + 2);
expect(tickSpy.withArgs('cls-ofv')).to.be.calledOnce;
whenViewportLayoutCompleteResolve();
return perf.whenViewportLayoutComplete_().then(() => {
expect(tickSpy).to.have.callCount(initialCount + 1);
expect(tickSpy).to.have.callCount(initialCount + 2);
expect(tickSpy.withArgs('ofv')).to.be.calledOnce;
return whenFirstVisiblePromise.then(() => {
expect(tickSpy).to.have.callCount(initialCount + 2);
expect(tickSpy).to.have.callCount(initialCount + 3);
expect(tickSpy.withArgs('pc')).to.be.calledOnce;
expect(Number(tickSpy.withArgs('pc').args[0][1])).to.equal(400);
});
Expand Down Expand Up @@ -965,7 +967,7 @@ describes.realWin('PeformanceObserver metrics', {amp: true}, (env) => {

const perf = Services.performanceFor(env.win);

expect(perf.events_.length).to.equal(3);
expect(perf.events_.length).to.equal(4);
expect(perf.events_[0]).to.be.jsonEqual(
{
label: 'fp',
Expand All @@ -978,6 +980,10 @@ describes.realWin('PeformanceObserver metrics', {amp: true}, (env) => {
{
label: 'fcpv',
delta: 15,
},
{
label: 'cls-fcp',
delta: 15,
}
);

Expand Down Expand Up @@ -1027,7 +1033,7 @@ describes.realWin('PeformanceObserver metrics', {amp: true}, (env) => {
};
// Fake a triggering of the first-input event.
performanceObserver.triggerCallback(list);
expect(perf.events_.length).to.equal(3);
expect(perf.events_.length).to.equal(4);
expect(perf.events_[0]).to.be.jsonEqual(
{
label: 'fp',
Expand All @@ -1040,6 +1046,10 @@ describes.realWin('PeformanceObserver metrics', {amp: true}, (env) => {
{
label: 'fcpv',
delta: 15,
},
{
label: 'cls-fcp',
delta: 15,
}
);
});
Expand Down