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 a few milliseconds on the
q4000 demo overall from 10ms to 5ms (Chrome), and seems to move some
unattributed costs to outside the critical path.
  • Loading branch information
Krinkle committed Jul 24, 2024
1 parent 89c7c8c commit a729421
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/core/reporters/HtmlReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,10 @@ export default class HtmlReporter {
// the original urlParams in makeUrl()
this.hidepassed = value;
const tests = this.elementTests;
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 @@ -274,13 +274,18 @@ export default class HtmlReporter {
}
}

for (const hiddenTest of this.hiddenTests) {
tests.removeChild(hiddenTest);
// Optimization: Avoid for-of iterator overhead.
for (let i = 0; i < this.hiddenTests.length; i++) {
tests.removeChild(this.hiddenTests[i]);
}
} else {
while (this.hiddenTests.length) {
tests.appendChild(this.hiddenTests.shift());
// Optimization: Avoid Array.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 < this.hiddenTests.length; i++) {
tests.appendChild(this.hiddenTests[i]);
}
this.hiddenTests.length = 0;
}
window.history.replaceState(null, '', updatedUrl);
} else {
Expand Down

0 comments on commit a729421

Please sign in to comment.