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 (diff between focus start and type start) #48365

Closed
wants to merge 2 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
32 changes: 13 additions & 19 deletions packages/e2e-tests/specs/performance/post-editor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import {
getTypingEventDurations,
getClickEventDurations,
getHoverEventDurations,
getSelectionEventDurations,
getLoadingDurations,
sum,
getDiffBetweenEventStarts,
} from './utils';

jest.setTimeout( 1000000 );
Expand Down Expand Up @@ -162,24 +162,16 @@ describe( 'Post Editor Performance', () => {
// The timeout should be big enough to allow all async tasks tor run.
// And also to allow Rich Text to mark the change as persistent.
// eslint-disable-next-line no-restricted-syntax
await page.waitForTimeout( 2000 );
await page.keyboard.type( 'x' );
}
await page.keyboard.type( 'x' );
await page.tracing.stop();
traceResults = JSON.parse( readFile( traceFile ) );
const [ keyDownEvents, keyPressEvents, keyUpEvents ] =
getTypingEventDurations( traceResults );
if (
keyDownEvents.length === keyPressEvents.length &&
keyPressEvents.length === keyUpEvents.length
) {
// The first character typed triggers a longer time (isTyping change)
// It can impact the stability of the metric, so we exclude it.
for ( let j = 1; j < keyDownEvents.length; j++ ) {
results.type.push(
keyDownEvents[ j ] + keyPressEvents[ j ] + keyUpEvents[ j ]
);
}
const [ keyDownEvents ] = getTypingEventDurations( traceResults );
// The first character typed triggers a longer time (isTyping change)
// It can impact the stability of the metric, so we exclude it.
for ( let j = 1; j < keyDownEvents.length; j++ ) {
results.type.push( keyDownEvents[ j ] - keyDownEvents[ j - 1 ] );
}
} );

Expand Down Expand Up @@ -247,13 +239,15 @@ describe( 'Post Editor Performance', () => {
categories: [ 'devtools.timeline' ],
} );
await paragraphs[ j ].click();
await page.keyboard.type( 'a' );
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 )
getDiffBetweenEventStarts(
traceResults,
'pointerdown',
'keydown'
)
);
}
} );
Expand Down
50 changes: 18 additions & 32 deletions packages/e2e-tests/specs/performance/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,46 +15,31 @@ export function deleteFile( filePath ) {
}
}

function isEvent( item ) {
function isEvent( item, type ) {
return (
item.cat === 'devtools.timeline' &&
item.name === 'EventDispatch' &&
item.dur &&
item.args &&
item.args.data
item.args.data &&
item.args.data.type === type
);
}

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

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

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

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

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

function isClickEvent( item ) {
return isEvent( item ) && item.args.data.type === 'click';
return isEvent( item, 'click' );
}

function isMouseOverEvent( item ) {
return isEvent( item ) && item.args.data.type === 'mouseover';
return isEvent( item, 'mouseover' );
}

function isMouseOutEvent( item ) {
return isEvent( item ) && item.args.data.type === 'mouseout';
return isEvent( item, 'mouseout' );
}

function getEventDurationsForType( trace, filterFunction ) {
Expand All @@ -63,19 +48,20 @@ 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 ),
getEventDurationsForType( trace, isKeyPressEvent ),
getEventDurationsForType( trace, isKeyUpEvent ),
];
return [ getEventStartForType( trace, isKeyDownEvent ) ];
}

export function getSelectionEventDurations( trace ) {
return [
getEventDurationsForType( trace, isFocusEvent ),
getEventDurationsForType( trace, isFocusInEvent ),
];
export function getDiffBetweenEventStarts( trace, aType, bType ) {
const aEvent = trace.traceEvents.find( ( item ) => isEvent( item, aType ) );
const bEvent = trace.traceEvents.find( ( item ) => isEvent( item, bType ) );
return ( bEvent.ts - aEvent.ts ) / 1000;
}

export function getClickEventDurations( trace ) {
Expand Down