Bug 1261738: Try to avoid overlapping FX_TAB_SWITCH_TOTAL_MS stopwatches. r?mconley draft
authorKris Maglione <maglione.k@gmail.com>
Sun, 03 Apr 2016 19:06:57 -0700
changeset 347234 d2fabb1abc45dc1193bf4a0809d101302242511d
parent 347223 d50240348923d829500a0284d832599804987e5c
child 347235 48b437e7b7dd843da3e1c6f0792a17f6b0509541
push id14523
push usermaglione.k@gmail.com
push dateMon, 04 Apr 2016 02:08:04 +0000
reviewersmconley
bugs1261738
milestone48.0a1
Bug 1261738: Try to avoid overlapping FX_TAB_SWITCH_TOTAL_MS stopwatches. r?mconley MozReview-Commit-ID: JSSvsbL6q1n
browser/base/content/tabbrowser.xml
--- a/browser/base/content/tabbrowser.xml
+++ b/browser/base/content/tabbrowser.xml
@@ -1013,36 +1013,50 @@
       <method name="updateTitlebar">
         <body>
           <![CDATA[
             this.ownerDocument.title = this.getWindowTitleForBrowser(this.mCurrentBrowser);
           ]]>
         </body>
       </method>
 
+      <field name="_tabSwitchID">null</field>
+
       <method name="updateCurrentBrowser">
         <parameter name="aForceUpdate"/>
         <body>
           <![CDATA[
             var newBrowser = this.getBrowserAtIndex(this.tabContainer.selectedIndex);
             if (this.mCurrentBrowser == newBrowser && !aForceUpdate)
               return;
 
             if (!aForceUpdate) {
               TelemetryStopwatch.start("FX_TAB_SWITCH_UPDATE_MS");
               if (!gMultiProcessBrowser) {
                 // old way of measuring tab paint which is not valid with e10s.
                 // Waiting until the next MozAfterPaint ensures that we capture
                 // the time it takes to paint, upload the textures to the compositor,
                 // and then composite.
+                if (this._tabSwitchID) {
+                  TelemetryStopwatch.cancel("FX_TAB_SWITCH_TOTAL_MS");
+                }
+
+                let tabSwitchID = Symbol();
+
                 TelemetryStopwatch.start("FX_TAB_SWITCH_TOTAL_MS");
-                window.addEventListener("MozAfterPaint", function onMozAfterPaint() {
-                  TelemetryStopwatch.finish("FX_TAB_SWITCH_TOTAL_MS");
+                this._tabSwitchID = tabSwitchID;
+
+                let onMozAfterPaint = () => {
+                  if (this._tabSwitchID === tabSwitchID) {
+                    TelemetryStopwatch.finish("FX_TAB_SWITCH_TOTAL_MS");
+                    this._tabSwitchID = null;
+                  }
                   window.removeEventListener("MozAfterPaint", onMozAfterPaint);
-                });
+                }
+                window.addEventListener("MozAfterPaint", onMozAfterPaint);
               }
             }
 
             var oldTab = this.mCurrentTab;
 
             // Preview mode should not reset the owner
             if (!this._previewMode && !oldTab.selected)
               oldTab.owner = null;