Skip to content

Commit

Permalink
Avoid relying on DOM events to measure the loading time (#25288)
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad authored Sep 14, 2020
1 parent 1702ef0 commit 7196307
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 42 deletions.
5 changes: 0 additions & 5 deletions bin/plugin/commands/performance.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const config = require( '../config' );
* @typedef WPRawPerformanceResults
*
* @property {number[]} load Load Time.
* @property {number[]} domcontentloaded DOM Contentloaded time.
* @property {number[]} type Average type time.
* @property {number[]} focus Average block selection time.
*/
Expand All @@ -37,7 +36,6 @@ const config = require( '../config' );
* @typedef WPPerformanceResults
*
* @property {number} load Load Time.
* @property {number} domcontentloaded DOM Contentloaded time.
* @property {number} type Average type time.
* @property {number} minType Minium type time.
* @property {number} maxType Maximum type time.
Expand All @@ -49,7 +47,6 @@ const config = require( '../config' );
* @typedef WPFormattedPerformanceResults
*
* @property {string=} load Load Time.
* @property {string=} domcontentloaded DOM Contentloaded time.
* @property {string=} type Average type time.
* @property {string=} minType Minium type time.
* @property {string=} maxType Maximum type time.
Expand Down Expand Up @@ -106,7 +103,6 @@ function formatTime( number ) {
function curateResults( results ) {
return {
load: average( results.load ),
domcontentloaded: average( results.domcontentloaded ),
type: average( results.type ),
minType: Math.min( ...results.type ),
maxType: Math.max( ...results.type ),
Expand Down Expand Up @@ -164,7 +160,6 @@ async function runTestSuite( testSuite, performanceTestDirectory ) {
const medians = mapValues(
{
load: results.map( ( r ) => r.load ),
domcontentloaded: results.map( ( r ) => r.domcontentloaded ),
type: results.map( ( r ) => r.type ),
minType: results.map( ( r ) => r.minType ),
maxType: results.map( ( r ) => r.maxType ),
Expand Down
7 changes: 2 additions & 5 deletions packages/e2e-tests/config/performance-reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,13 @@ class PerformanceReporter {
}

const results = readFileSync( filepath, 'utf8' );
const { load, domcontentloaded, type, focus } = JSON.parse( results );
const { load, type, focus } = JSON.parse( results );

if ( load && load.length ) {
// eslint-disable-next-line no-console
console.log( `
${ title( 'Loading Time:' ) }
Average time to load: ${ success( round( average( load ) ) + 'ms' ) }
Average time to DOM content load: ${ success(
round( average( domcontentloaded ) ) + 'ms'
) }` );
Average time to load: ${ success( round( average( load ) ) + 'ms' ) }` );
}

if ( type && type.length ) {
Expand Down
20 changes: 4 additions & 16 deletions packages/e2e-tests/specs/performance/post-editor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ describe( 'Post Editor Performance', () => {
it( 'Loading, typing and selecting blocks', async () => {
const results = {
load: [],
domcontentloaded: [],
type: [],
focus: [],
};
Expand Down Expand Up @@ -105,21 +104,10 @@ describe( 'Post Editor Performance', () => {

// Measuring loading time
while ( i-- ) {
await page.reload( { waitUntil: [ 'domcontentloaded', 'load' ] } );
const timings = JSON.parse(
await page.evaluate( () =>
JSON.stringify( window.performance.timing )
)
);
const {
navigationStart,
domContentLoadedEventEnd,
loadEventEnd,
} = timings;
results.load.push( loadEventEnd - navigationStart );
results.domcontentloaded.push(
domContentLoadedEventEnd - navigationStart
);
const startTime = new Date();
await page.reload();
await page.waitForSelector( '.wp-block' );
results.load.push( new Date() - startTime );
}

// Measuring typing performance
Expand Down
20 changes: 4 additions & 16 deletions packages/e2e-tests/specs/performance/site-editor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ describe( 'Site Editor Performance', () => {
it( 'Loading', async () => {
const results = {
load: [],
domcontentloaded: [],
type: [],
focus: [],
};
Expand All @@ -51,21 +50,10 @@ describe( 'Site Editor Performance', () => {

// Measuring loading time
while ( i-- ) {
await page.reload( { waitUntil: [ 'domcontentloaded', 'load' ] } );
const timings = JSON.parse(
await page.evaluate( () =>
JSON.stringify( window.performance.timing )
)
);
const {
navigationStart,
domContentLoadedEventEnd,
loadEventEnd,
} = timings;
results.load.push( loadEventEnd - navigationStart );
results.domcontentloaded.push(
domContentLoadedEventEnd - navigationStart
);
const startTime = new Date();
await page.reload();
await page.waitForSelector( '.wp-block' );
results.load.push( new Date() - startTime );
}

const resultsFilename = basename( __filename, '.js' ) + '.results.json';
Expand Down

0 comments on commit 7196307

Please sign in to comment.