Bug 1589744: Don't update hidden tabs when not necessary r=davidwalsh
authorSorin Davidoi <sorin.davidoi@protonmail.com>
Thu, 31 Oct 2019 09:38:47 +0000
changeset 500086 86bee6f6a880d28807aca41824bb5aa85ffc4ba5
parent 500085 60cccadbeaf01eee779400d8ae6f0c6e5f80da1c
child 500087 182daeba07e6bf9be6ebfda39cfb47cd3066b707
push id36754
push userbtara@mozilla.com
push dateFri, 01 Nov 2019 16:13:11 +0000
treeherdermozilla-central@475496111203 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdavidwalsh
bugs1589744
milestone72.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1589744: Don't update hidden tabs when not necessary r=davidwalsh They only need to be updated from `componentDidUpdate` if the open tabs have changed. Before: https://perfht.ml/32w6iwg After: https://perfht.ml/2Bqk7R0 Diff: https://perfht.ml/2pvNyhW Differential Revision: https://phabricator.services.mozilla.com/D49782
devtools/client/debugger/src/components/Editor/Tabs.js
--- a/devtools/client/debugger/src/components/Editor/Tabs.js
+++ b/devtools/client/debugger/src/components/Editor/Tabs.js
@@ -53,16 +53,33 @@ type Props = {
   isPaused: boolean,
 };
 
 type State = {
   dropdownShown: boolean,
   hiddenTabs: SourcesList,
 };
 
+function haveTabSourcesChanged(
+  tabSources: SourcesList,
+  prevTabSources: SourcesList
+): boolean {
+  if (tabSources.length !== prevTabSources.length) {
+    return true;
+  }
+
+  for (let i = 0; i < tabSources.length; ++i) {
+    if (tabSources[i].id !== prevTabSources[i].id) {
+      return true;
+    }
+  }
+
+  return false;
+}
+
 class Tabs extends PureComponent<Props, State> {
   onTabContextMenu: Function;
   showContextMenu: Function;
   updateHiddenTabs: Function;
   toggleSourcesDropdown: Function;
   renderDropdownSource: Function;
   renderTabs: Function;
   renderDropDown: Function;
@@ -78,17 +95,20 @@ class Tabs extends PureComponent<Props, 
     };
 
     this.onResize = debounce(() => {
       this.updateHiddenTabs();
     });
   }
 
   componentDidUpdate(prevProps: Props) {
-    if (!(prevProps === this.props)) {
+    if (
+      this.props.selectedSource !== prevProps.selectedSource ||
+      haveTabSourcesChanged(this.props.tabSources, prevProps.tabSources)
+    ) {
       this.updateHiddenTabs();
     }
   }
 
   componentDidMount() {
     window.requestIdleCallback(this.updateHiddenTabs);
     window.addEventListener("resize", this.onResize);
     window.document