From 4a30a91b1b4cad6d686b749037f7a2ce548fdd05 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Sun, 14 Jul 2024 20:19:25 +0100 Subject: [PATCH] HTML Reporter: Optimize hidepassed click handler for large test suites --- src/core/reporters/HtmlReporter.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/core/reporters/HtmlReporter.js b/src/core/reporters/HtmlReporter.js index 86a40791a..0170f6cf9 100644 --- a/src/core/reporters/HtmlReporter.js +++ b/src/core/reporters/HtmlReporter.js @@ -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 : ''; @@ -274,13 +274,16 @@ 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. + for (let i = 0; i < this.hiddenTests.length; i++) { + tests.appendChild(this.hiddenTests[i]); } + this.hiddenTests.length = 0; } window.history.replaceState(null, '', updatedUrl); } else {