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

Performance: improve focus metric calculation #48362

Closed
wants to merge 4 commits into from
Closed
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
26 changes: 14 additions & 12 deletions packages/e2e-tests/specs/performance/post-editor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
getHoverEventDurations,
getSelectionEventDurations,
getLoadingDurations,
sum,
} from './utils';

jest.setTimeout( 1000000 );
Expand Down Expand Up @@ -235,22 +236,26 @@ describe( 'Post Editor Performance', () => {
it( 'Selecting blocks', async () => {
await load1000Paragraphs();
const paragraphs = await canvas().$$( '.wp-block' );
await page.tracing.start( {
path: traceFile,
screenshots: false,
categories: [ 'devtools.timeline' ],
} );
await paragraphs[ 0 ].click();
for ( let j = 1; j <= 10; j++ ) {
// Wait for the browser to be idle before starting the monitoring.
// eslint-disable-next-line no-restricted-syntax
await page.waitForTimeout( 1000 );
await page.tracing.start( {
path: traceFile,
screenshots: false,
categories: [ 'devtools.timeline' ],
} );
await paragraphs[ j ].click();
await page.tracing.stop();
traceResults = JSON.parse( readFile( traceFile ) );
const allDurations = getSelectionEventDurations( traceResults );
results.focus.push(
allDurations.reduce( ( acc, eventDurations ) => {
return acc + sum( eventDurations );
}, 0 )
);
}
await page.tracing.stop();
traceResults = JSON.parse( readFile( traceFile ) );
const [ focusEvents ] = getSelectionEventDurations( traceResults );
results.focus = focusEvents;
} );

it( 'Opening persistent list view', async () => {
Expand Down Expand Up @@ -292,9 +297,6 @@ describe( 'Post Editor Performance', () => {
} );

it( 'Searching the inserter', async () => {
function sum( arr ) {
return arr.reduce( ( a, b ) => a + b, 0 );
}
await load1000Paragraphs();
await openGlobalBlockInserter();
for ( let j = 0; j < 10; j++ ) {
Expand Down
13 changes: 12 additions & 1 deletion packages/e2e-tests/specs/performance/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ function isFocusEvent( item ) {
return isEvent( item ) && item.args.data.type === 'focus';
}

function isFocusInEvent( item ) {
return isEvent( item ) && item.args.data.type === 'focusin';
}

function isClickEvent( item ) {
return isEvent( item ) && item.args.data.type === 'click';
}
Expand Down Expand Up @@ -68,7 +72,10 @@ export function getTypingEventDurations( trace ) {
}

export function getSelectionEventDurations( trace ) {
return [ getEventDurationsForType( trace, isFocusEvent ) ];
return [
getEventDurationsForType( trace, isFocusEvent ),
getEventDurationsForType( trace, isFocusInEvent ),
];
}

export function getClickEventDurations( trace ) {
Expand Down Expand Up @@ -113,3 +120,7 @@ export async function getLoadingDurations() {
};
} );
}

export function sum( arr ) {
return arr.reduce( ( a, b ) => a + b, 0 );
}