Skip to content

Commit

Permalink
HTML Reporter: Faster "Hide passed" toggling on large test suites
Browse files Browse the repository at this point in the history
Optimize the hidepassed click handler for large test suites by
avoiding internal function call overhead for the iterator, as well
as copying cost for the array. Shaves off ~100ms milliseconds on the
q4000 demo 1.65s to 1.5s (Chrome, CPU throttle 6x), and seems to defer
some unattributed costs to outside the critical path.

Cherry-picked from a729421 (3.0.0-dev).
  • Loading branch information
Krinkle committed Jan 19, 2025
1 parent 567ab7d commit b13ade0
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/html-reporter/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,9 @@ const stats = {
config[field.name] = value || false;
let tests = id('qunit-tests');
if (tests) {
const length = tests.children.length;
const children = tests.children;

if (field.checked) {
const length = tests.children.length;
const children = tests.children;
for (let i = 0; i < length; i++) {
const test = children[i];
const className = test ? test.className : '';
Expand All @@ -211,13 +210,18 @@ const stats = {
}
}

for (const hiddenTest of hiddenTests) {
tests.removeChild(hiddenTest);
// Optimization: Avoid `for-of` iterator overhead.
for (let i = 0; i < hiddenTests.length; i++) {
tests.removeChild(hiddenTests[i]);
}
} else {
while (hiddenTests.length) {
tests.appendChild(hiddenTests.shift());
// Optimization: Avoid `while (arr.length) arr.shift()` which would mutate the array many times.
// As of Chrome 126, HTMLElement.append(...hiddenTests) is still slower than
// calling appendChild in a loop.
for (let i = 0; i < hiddenTests.length; i++) {
tests.appendChild(hiddenTests[i]);
}
hiddenTests.length = 0;
}
}
window.history.replaceState(null, '', updatedUrl);
Expand Down

0 comments on commit b13ade0

Please sign in to comment.