"no-dup-id" increases runtime by 4x (400%)
On a page with 500 id= it increases the runtime from 1 to 4 seconds if the rule is enabled
Possible avenues to improve performance:
-
remove
const relevant = elements.filter(isRelevant);
and call isRelevant in thefor
loop directly after it, since "filter" causes a full 2nd iteration -
run the checks of
isRelevant
directly in the loop, to avoid duplicate calls/checks togetAttribute("id")
as well as if checks that are currently ignored anyway (e.g./* istanbul ignore next: this has already been tested in isRelevant once but for type-safety it is checked again */
) -
getExisting(
callselement.closest("template")
every time, however the use of "template" is quite rare for HTML pages overall. Possibly check if the document has "template" at all somewhere early/globally (since I think similar template checks exist in other rules) and skip theelement.closest("template")
checks if the page doesn't contain a template at all. Since it currently has to parse the whole document for every element if there are no templates. -
for 3)
getExisting
- if there is no "template", skip the call togetExisting
since the group is always document.root, thus avoiding unnecessarily callingcacheGet
(and also the if(existing) however that isn't really slow anyway), therefore the "existing" can be set once before the "for" loop in setup() -
continue after
this.report(el,
Duplicate ID "${id}", attr.valueLocation);
since the id already exists, so the call to.add(
is wasted