Bug 1456056 - Part 1. Improve the performance of toolbar tabs overflow. r?jdescottes draft
authorMantaroh Yoshinaga <mantaroh@gmail.com>
Thu, 31 May 2018 10:22:31 +0900
changeset 801946 c1d7c7e7452aad965ff6620af36141264444bb37
parent 801916 3931f461c8e8668a264d52b51a4524aac39a7a16
child 801947 8220be9ef76ff442bb8ecc41ee6a9e50dfeba5cc
push id111785
push userbmo:mantaroh@gmail.com
push dateThu, 31 May 2018 01:28:25 +0000
reviewersjdescottes
bugs1456056
milestone62.0a1
Bug 1456056 - Part 1. Improve the performance of toolbar tabs overflow. r?jdescottes This patch will two impprove performances: * Remove unnecesarry reflow by using the DOMWindowUtils.getBoundsWithoutFlushing(). This is a tiny performance improvement. Previous code will reflow on each tab width caclculation. * Change requestIdleCallback's timeout to 100ms. If user resize the devtool's width over time, overflow calculation will occur every 300ms. This patch will reduce this delay. MozReview-Commit-ID: FxZuK0wGxHk
devtools/client/framework/components/ToolboxTabs.js
--- a/devtools/client/framework/components/ToolboxTabs.js
+++ b/devtools/client/framework/components/ToolboxTabs.js
@@ -105,21 +105,26 @@ class ToolboxTabs extends Component {
     return !this.equalToolIdArray(prevPanels, nextPanels);
   }
 
   /**
    * Update the Map of tool id and tool tab width.
    */
   updateCachedToolTabsWidthMap() {
     let thisNode = findDOMNode(this);
+    let utils = window.QueryInterface(Ci.nsIInterfaceRequestor)
+        .getInterface(Ci.nsIDOMWindowUtils);
+    // Force a reflow before calling getBoundingWithoutFlushing on each tab.
+    thisNode.clientWidth;
+
     for (let tab of thisNode.querySelectorAll(".devtools-tab")) {
       let tabId = tab.id.replace("toolbox-tab-", "");
       if (!this._cachedToolTabsWidthMap.has(tabId)) {
-        let cs = getComputedStyle(tab);
-        this._cachedToolTabsWidthMap.set(tabId, parseInt(cs.width, 10));
+        let rect = utils.getBoundsWithoutFlushing(tab);
+        this._cachedToolTabsWidthMap.set(tabId, rect.width);
       }
     }
   }
 
   /**
    * Update the overflowed tab array from currently displayed tool tab.
    * If calculated result is the same as the current overflowed tab array, this
    * function will not update state.
@@ -172,17 +177,17 @@ class ToolboxTabs extends Component {
       this.setState({ overflowedTabIds: willOverflowTabs });
     }
   }
 
   resizeHandler(evt) {
     window.cancelIdleCallback(this._resizeTimerId);
     this._resizeTimerId = window.requestIdleCallback(() => {
       this.updateOverflowedTabs();
-    }, { timeout: 300 });
+    }, { timeout: 100 });
   }
 
   /**
    * Render a button to access overflowed tools, displayed only when the toolbar
    * presents an overflow.
    */
   renderToolsChevronButton() {
     let {