Use of :has() pseudo-selector hurts performance on some pages

Open
#226 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
css

Research direction

Start by reviewing the :has() selectors in shutup.css, the context in RickyRomero/shut-up-webextension#68, and the linked slow-scrolling example. Compare scrolling performance with those selectors removed, then determine and document which mitigation is accepted; completion is not defined by the issue yet.

Written by the indexing model from the issue text.

Description

See RickyRomero/shut-up-webextension#68 for more context. I removed all selectors that make use of :has() from shutup.css and it greatly improved performance on my 2018 Intel MacBook Pro when scrolling this page.

We've been making use of :has() more frequently for hiding comments on pages. This has been incredibly useful since it lets you query based on the contents of a given selector, and modern web apps are getting increasingly harder to block comments on because of the abstractions used to build them. But on web apps that make frequent modifications to the DOM, this pseudoselector causes the browser to bog down when recalculating styles.

I need to do some more investigation to see if there are any optimizations I can make that still let us use :has() in shutup.css, but wanted to file this here in case you had any ideas for dealing with this problem.


My initial thought, if we can't optimize this problem away, is to move any use of :has() into another stylesheet (shutup-heavy.css) that people can add if they want better comment blocking at the expense of performance. I don't love this idea.

Another approach could be to ban the use of :has() and require using more performant selectors instead, but this would limit our ability to block comments by quite a bit.

Or, we could require any use of :has() be scoped to a specific domain name in the browser extension. We could leave :has() in shutup.css for people who use it as a user stylesheet or with Stylus, but in the browser extension I could have a build step which scopes the selectors to specific domain names.


Just spitballing here, again, I haven't looked into whether this can be optimized around or not by writing :has() selectors differently, but wanted to see what you think.

Dominant language
CSS
Stars
268
Forks
61
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from panicsteve/shutup-css

All issues in panicsteve/shutup-css

Similar issues

More Performance issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.