Skip to content

Commit

Permalink
Performance: improve focus metric (diff between focus start and type …
Browse files Browse the repository at this point in the history
…start)
  • Loading branch information
ellatrix committed Feb 23, 2023
1 parent 8c68626 commit b848d1d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
20 changes: 11 additions & 9 deletions packages/e2e-tests/specs/performance/post-editor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,22 +235,24 @@ 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.keyboard.type( 'a' );
await page.tracing.stop();
traceResults = JSON.parse( readFile( traceFile ) );
const [ focusEvents, keyDownEvents ] =
getSelectionEventDurations( traceResults );
results.focus.push( keyDownEvents[ 0 ] - focusEvents[ 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
11 changes: 10 additions & 1 deletion packages/e2e-tests/specs/performance/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ function getEventDurationsForType( trace, filterFunction ) {
.map( ( item ) => item.dur / 1000 );
}

function getEventStartForType( trace, filterFunction ) {
return trace.traceEvents
.filter( filterFunction )
.map( ( item ) => item.ts / 1000 );
}

export function getTypingEventDurations( trace ) {
return [
getEventDurationsForType( trace, isKeyDownEvent ),
Expand All @@ -68,7 +74,10 @@ export function getTypingEventDurations( trace ) {
}

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

export function getClickEventDurations( trace ) {
Expand Down

0 comments on commit b848d1d

Please sign in to comment.