src/service/performance-impl.js
/**
   * Measure the delay the user perceives of how long it takes
   * to load the initial viewport.
   * @private
   */
Measure the delay the user perceives of how long it takes
to load the initial viewport.
@private
Measure the delay the user perceives of how long it takes to load the initial viewport . @private
measureUserPerceivedVisualCompletenessTime_() {
    const didStartInPrerender = !this.viewer_.hasBeenVisible();
    let docVisibleTime = didStartInPrerender ? -1 : this.initTime_;
    if (didStartInPrerender) {
      this.viewer_.whenFirstVisible().then(() => {
        docVisibleTime = this.win.Date.now();
      });
    }
    this.whenViewportLayoutComplete_().then(() => {
      if (didStartInPrerender) {
        const userPerceivedVisualCompletenesssTime = docVisibleTime > -1
            ? (this.win.Date.now() - docVisibleTime)
            : 0;
        this.viewer_.whenFirstVisible().then(() => {
          this.tickDelta('pc', userPerceivedVisualCompletenesssTime);
        });
        this.prerenderComplete_(userPerceivedVisualCompletenesssTime);
      } else {
        this.tick('pc');
        this.prerenderComplete_(this.win.Date.now() - docVisibleTime);
      }
      this.flush();
    });
  }
measureUserPerceivedVisualCompletenessTime_ ( ) { const didStartInPrerender = ! this . viewer_ . hasBeenVisible ( ) ; let docVisibleTime = didStartInPrerender ? - 1 : this . initTime_ ; if ( didStartInPrerender ) { this . viewer_ . whenFirstVisible ( ) . then ( ( ) => { docVisibleTime = this . win . Date . now ( ) ; } ) ; } this . whenViewportLayoutComplete_ ( ) . then ( ( ) => { if ( didStartInPrerender ) { const userPerceivedVisualCompletenesssTime = docVisibleTime > - 1 ? ( this . win . Date . now ( ) - docVisibleTime ) : 0 ; this . viewer_ . whenFirstVisible ( ) . then ( ( ) => { this . tickDelta ( 'pc' , userPerceivedVisualCompletenesssTime ) ; } ) ; this . prerenderComplete_ ( userPerceivedVisualCompletenesssTime ) ; } else { this . tick ( 'pc' ) ; this . prerenderComplete_ ( this . win . Date . now ( ) - docVisibleTime ) ; } this . flush ( ) ; } ) ; }
Measure the delay the user perceives of how long it takes
 to load the initial viewport.
Measure the delay the user perceives of how long it takes to load the initial viewport .
// This is only relevant if the viewer is in prerender mode. // (hasn't been visible yet, ever at this point) //  Prerender was complete before visibility. // We only tick this if the page eventually becomes visible, // since otherwise we heavily skew the metric towards the // 0 case, since pre-renders that are never used are highly // likely to fully load before they are never used :) // If it didnt start in prerender, no need to calculate anything // and we just need to tick `pc`. (it will give us the relative // time since the viewer initialized the timer) // We don't have the actual csi timer's clock start time, // so we just have to use `docVisibleTime`.