Skip to content

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

@RickyRomero

Description

@RickyRomero

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions