Skip to content

Commit b13ade0

Browse files
committed
HTML Reporter: Faster "Hide passed" toggling on large test suites
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).
1 parent 567ab7d commit b13ade0

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/html-reporter/html.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,9 @@ const stats = {
196196
config[field.name] = value || false;
197197
let tests = id('qunit-tests');
198198
if (tests) {
199-
const length = tests.children.length;
200-
const children = tests.children;
201-
202199
if (field.checked) {
200+
const length = tests.children.length;
201+
const children = tests.children;
203202
for (let i = 0; i < length; i++) {
204203
const test = children[i];
205204
const className = test ? test.className : '';
@@ -211,13 +210,18 @@ const stats = {
211210
}
212211
}
213212

214-
for (const hiddenTest of hiddenTests) {
215-
tests.removeChild(hiddenTest);
213+
// Optimization: Avoid `for-of` iterator overhead.
214+
for (let i = 0; i < hiddenTests.length; i++) {
215+
tests.removeChild(hiddenTests[i]);
216216
}
217217
} else {
218-
while (hiddenTests.length) {
219-
tests.appendChild(hiddenTests.shift());
218+
// Optimization: Avoid `while (arr.length) arr.shift()` which would mutate the array many times.
219+
// As of Chrome 126, HTMLElement.append(...hiddenTests) is still slower than
220+
// calling appendChild in a loop.
221+
for (let i = 0; i < hiddenTests.length; i++) {
222+
tests.appendChild(hiddenTests[i]);
220223
}
224+
hiddenTests.length = 0;
221225
}
222226
}
223227
window.history.replaceState(null, '', updatedUrl);

0 commit comments

Comments
 (0)