Skip to content

"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:

  1. remove const relevant = elements.filter(isRelevant); and call isRelevant in the for loop directly after it, since "filter" causes a full 2nd iteration

  2. run the checks of isRelevant directly in the loop, to avoid duplicate calls/checks to getAttribute("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 */)

  3. getExisting( calls element.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 the element.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.

  4. for 3) getExisting - if there is no "template", skip the call to getExisting since the group is always document.root, thus avoiding unnecessarily calling cacheGet (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()

  5. continue after this.report(el, Duplicate ID "${id}", attr.valueLocation); since the id already exists, so the call to .add( is wasted

Edited by Hub Misto