Bug 1705827 - keep updating CPU and memory values in about:processes when sorting changes are disabled due to recent mouse events, r=dthayer.
authorFlorian Quèze <florian@queze.net>
Wed, 21 Apr 2021 18:05:23 +0000
changeset 577006 9c1aa135e1b5d11bfd1b53e71c45f22564e498c5
parent 577005 e5aa7733e1aea8c6319eae58e084a145c57b6e59
child 577007 d222a009f9df20b8fe164ac0168579c23c367692
push id141675
push userfqueze@mozilla.com
push dateWed, 21 Apr 2021 18:07:57 +0000
treeherderautoland@9c1aa135e1b5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdthayer
bugs1705827
milestone90.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 1705827 - keep updating CPU and memory values in about:processes when sorting changes are disabled due to recent mouse events, r=dthayer. Depends on D112537 Differential Revision: https://phabricator.services.mozilla.com/D112538
toolkit/components/aboutprocesses/content/aboutProcesses.js
--- a/toolkit/components/aboutprocesses/content/aboutProcesses.js
+++ b/toolkit/components/aboutprocesses/content/aboutProcesses.js
@@ -417,16 +417,26 @@ var View = {
 
     if (insertPoint) {
       while ((nextRow = insertPoint.nextSibling)) {
         this._removeRow(nextRow);
       }
       this._removeRow(insertPoint);
     }
   },
+  // If we are not going to display the updated list of rows, drop references
+  // to rows that haven't been inserted in the DOM tree.
+  discardUpdate() {
+    for (let row of this._orderedRows) {
+      if (!row.parentNode) {
+        this._rowsById.delete(row.rowId);
+      }
+    }
+    this._orderedRows = [];
+  },
   insertAfterRow(row) {
     let tbody = row.parentNode;
     let nextRow;
     while ((nextRow = this._orderedRows.shift())) {
       tbody.insertBefore(nextRow, row.nextSibling);
     }
   },
 
@@ -1147,23 +1157,16 @@ var Control = {
     await wait(0);
 
     await this._updateDisplay(force);
   },
 
   // The force parameter can force a full update even when the mouse has been
   // moved recently.
   async _updateDisplay(force = false) {
-    if (
-      !force &&
-      Date.now() - this._lastMouseEvent < TIME_BEFORE_SORTING_AGAIN
-    ) {
-      return;
-    }
-
     let counters = State.getCounters();
     let units = await gPromisePrefetchedUnits;
 
     // We reset `_hungItems`, based on the assumption that the process hang
     // monitor will inform us again before the next update. Since the process hang monitor
     // pings its clients about once per second and we update about once per 2 seconds
     // (or more if the mouse moves), we should be ok.
     let hungItems = this._hungItems;
@@ -1198,16 +1201,30 @@ var Control = {
         previousProcess.displayRank != process.displayRank
       ) {
         // Add a separation between successive categories of processes.
         processRow.classList.add("separate-from-previous-process-group");
       }
       previousProcess = process;
     }
 
+    if (
+      !force &&
+      Date.now() - this._lastMouseEvent < TIME_BEFORE_SORTING_AGAIN
+    ) {
+      // If there has been a recent mouse event, we don't want to reorder,
+      // add or remove rows so that the table content under the mouse pointer
+      // doesn't change when the user might be about to click to close a tab
+      // or kill a process.
+      // We didn't return earlier because updating CPU and memory values is
+      // still valuable.
+      View.discardUpdate();
+      return;
+    }
+
     View.commit();
 
     // Reset the selectedRow field if that row is no longer in the DOM
     // to avoid keeping forever references to dead processes.
     if (this.selectedRow && !this.selectedRow.parentNode) {
       this.selectedRow = null;
     }
   },