@@ -387,11 +387,14 @@ import DOMPurify from 'dompurify';
387387 return ;
388388 }
389389
390- var deferred , promise , thisObj , prefsGroups , i ;
390+ var deferred , promise , thisObj , prefsGroups , i , initVersion ;
391391
392392 deferred = new this . defer ( ) ;
393393 promise = deferred . promise ( ) ;
394394 thisObj = this ;
395+ this . initializationVersion = ( this . initializationVersion || 0 ) + 1 ;
396+ initVersion = this . initializationVersion ;
397+ this . startInitTiming ( initVersion ) ;
395398
396399 this . playerDeleted = false ; // reset after deletePlayer()
397400
@@ -410,12 +413,16 @@ import DOMPurify from 'dompurify';
410413 this . initSignLanguage ( ) ;
411414
412415 this . initPlayer ( ) . then ( function ( ) {
416+ thisObj . logInitTiming ( initVersion , 'initPlayer complete' ) ;
413417
414418 thisObj . getTracks ( ) . then ( function ( ) {
419+ thisObj . logInitTiming ( initVersion , 'getTracks complete' ) ;
415420
416421 thisObj . initDescription ( ) . then ( function ( ) {
422+ thisObj . logInitTiming ( initVersion , 'initDescription complete' ) ;
417423
418424 thisObj . setupTracks ( ) . then ( function ( ) {
425+ thisObj . logInitTiming ( initVersion , 'setupTracks complete' ) ;
419426 if ( thisObj . hasClosedDesc ) {
420427 if ( ! thisObj . $descDiv || ( thisObj . $descDiv && ! ( $ . contains ( thisObj . $ableDiv [ 0 ] , thisObj . $descDiv [ 0 ] ) ) ) ) {
421428 // descDiv either doesn't exist, or exists in an orphaned state
@@ -426,13 +433,16 @@ import DOMPurify from 'dompurify';
426433 thisObj . initSpeech ( 'init' ) ;
427434
428435 thisObj . setupTranscript ( ) . then ( function ( ) {
436+ thisObj . logInitTiming ( initVersion , 'setupTranscript complete' ) ;
429437
430438 thisObj . initStenoFrame ( ) . then ( function ( ) {
439+ thisObj . logInitTiming ( initVersion , 'initStenoFrame complete' ) ;
431440
432441 if ( thisObj . stenoMode && thisObj . $stenoFrame ) {
433442 thisObj . stenoFrameContents = thisObj . $stenoFrame . contents ( ) ;
434443 }
435444 thisObj . getMediaTimes ( ) . then ( function ( mediaTimes ) {
445+ thisObj . logInitTiming ( initVersion , 'getMediaTimes complete' ) ;
436446
437447 thisObj . duration = mediaTimes [ 'duration' ] ;
438448 thisObj . elapsed = mediaTimes [ 'elapsed' ] ;
@@ -467,9 +477,13 @@ import DOMPurify from 'dompurify';
467477 }
468478 thisObj . setupPopups ( ) ;
469479 thisObj . updateCaption ( ) ;
480+ thisObj . logInitTiming ( initVersion , 'core UI ready' ) ;
470481 thisObj . injectVTS ( ) ;
482+ thisObj . logInitTiming ( initVersion , 'vts ready' ) ;
471483 thisObj . populateChaptersDiv ( ) ;
484+ thisObj . logInitTiming ( initVersion , 'chapters ready' ) ;
472485 thisObj . showSearchResults ( ) ;
486+ thisObj . logInitTiming ( initVersion , 'search results ready' ) ;
473487
474488 // Go ahead and load media, without user requesting it
475489 // Ideally, we would wait until user clicks play, rather than unnecessarily consume their bandwidth
@@ -484,6 +498,7 @@ import DOMPurify from 'dompurify';
484498 // this is the second. Best to pause a bit before executing, to be sure all prior steps are complete
485499 setTimeout ( function ( ) {
486500 thisObj . refreshControls ( ) ;
501+ thisObj . logInitTiming ( initVersion , 'initialization complete' ) ;
487502 deferred . resolve ( ) ;
488503 } , 100 ) ;
489504 } ) ;
@@ -499,6 +514,34 @@ import DOMPurify from 'dompurify';
499514 return promise ;
500515 } ;
501516
517+ AblePlayer . prototype . getInitTimingNow = function ( ) {
518+ if ( typeof window !== 'undefined' && window . performance && typeof window . performance . now === 'function' ) {
519+ return window . performance . now ( ) ;
520+ }
521+ return Date . now ( ) ;
522+ } ;
523+
524+ AblePlayer . prototype . startInitTiming = function ( version ) {
525+ if ( ! this . debug ) {
526+ return ;
527+ }
528+ this . initTiming = this . initTiming || { } ;
529+ this . initTiming [ version ] = {
530+ start : this . getInitTimingNow ( )
531+ } ;
532+ console . log ( '[AblePlayer][init v' + version + '] start' ) ;
533+ } ;
534+
535+ AblePlayer . prototype . logInitTiming = function ( version , label ) {
536+ var elapsed , timing ;
537+ if ( ! this . debug || ! this . initTiming || ! this . initTiming [ version ] ) {
538+ return ;
539+ }
540+ timing = this . initTiming [ version ] ;
541+ elapsed = this . getInitTimingNow ( ) - timing . start ;
542+ console . log ( '[AblePlayer][init v' + version + '] ' + label + ': ' + elapsed . toFixed ( 1 ) + 'ms' ) ;
543+ } ;
544+
502545 AblePlayer . prototype . initPlayer = function ( ) {
503546
504547 var thisObj = this ;
0 commit comments