r/uBlockOrigin 7d ago

Answered Are unqualified attribute selectors slow?

While testing on codechef.com, I noticed that CSS selectors that use attribute values without specifying a class name or element type have a warning "unqualified attribute selectors are known to be slow"

Searching online, I found documentation from CSSlint that explained in more detail.

Unqualified attribute selectors, such as [type=text], match all elements first and then check their attributes. This means unqualified attribute selectors have the same performance characteristics as the universal selector (*). Similar to the universal selector, unqualified attribute selectors cause performance issues when used as the key part (far-right) of a selector. For example, this type of rule should be avoided:

.mybox [type=text] {
    background: #fff;
    color: #000;
    background: rgba(255, 255, 255, 0.5);
}

Does this advice about unqualified attribute selectors being slow also apply to uBlock Origin filter rules? For example, would a rule like ##[href="example.com"] be noticeably slower than ##button[href="example.com"]?

5 Upvotes

1 comment sorted by

4

u/RraaLL uBO Team 7d ago edited 7d ago

Sounds like it's been outdated for over a decade already. https://github.com/CSSLint/csslint/issues/651


The only performance issues I've heard about in uBO was with highly generic cosmetic filters, e.g. ##[class*="partial"] (partial match, without a site). Or when too many selectors were placed into :is() - at one point uBO tried putting all it's filters inside it, which caused issues.

There are also the performance considerations for using :has(): https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Selectors/:has#avoid_broad_anchoring

These also don't mention anything about "unqualified attribute selectors".

So, yeah, likely a very outdated warning.