Skip to content

Commit

Permalink
dashboard: don't scroll hidden log windows to avoid reflows
Browse files Browse the repository at this point in the history
This reduces CPU use by ~43% in Firefox and ~30% in Chrome.

Scroll log windows to the bottom only after they are unhidden again.
  • Loading branch information
ivan committed Jun 10, 2023
1 parent 9cf8f41 commit f7d5b1a
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions dashboard/assets/scripts/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ function addAnyChangeListener(elem, func) {
elem.addEventListener("input", func, false);
}

function scrollToBottom(elem) {
// Scroll to the bottom. To avoid serious performance problems in Firefox,
// use a big number instead of elem.scrollHeight.
elem.scrollTop = 999999;
}

/**
* Returns a function that gets the given property on any object passed in
*/
Expand Down Expand Up @@ -626,9 +632,10 @@ class JobsRenderer {
}
}

// Scroll to the bottom. To avoid serious performance problems in Firefox,
// use a big number instead of info.logWindow.scrollHeight.
info.logWindow.scrollTop = 999999;
// If hidden, don't scroll: this saves us reflows and half our CPU time in Firefox.
if (!info.logWindow.classList.contains("log-window-hidden")) {
scrollToBottom(info.logWindow);
}
}
}

Expand Down Expand Up @@ -671,6 +678,12 @@ class JobsRenderer {
// as seeing the full info.
this.setAligned(false);
}

// Hidden log windows aren't scrolled down while lines are added to them,
// but now that more are visible, we need to scroll them to the bottom.
for (const w of matchedWindows) {
scrollToBottom(w);
}
}

showNextPrev(offset) {
Expand Down

0 comments on commit f7d5b1a

Please sign in to comment.