saxamaphone69 / ss21

a fresh attempt at a 4chan userstyle
49 stars 2 forks source link

Selector Performance #25

Open saxamaphone69 opened 1 year ago

saxamaphone69 commented 1 year ago

https://blogs.windows.com/msedgedev/2023/01/17/the-truth-about-css-selector-performance/

After reading this article, ran it through the Edge DevTools.

Keep it mind that some of the selectors are actually from uBlock.

Screenshot 2023-01-18 105311 Screenshot 2023-01-18 105553 Screenshot 2023-01-18 105615

.stub ~ *
:where(b, strong, th, legend, .subject, .name)
.fileText .file-info:has(.fnswitch)
:where(button, input, option, select, textarea)

On page load seem to be the most expensive.

Other notable selectors are

::selection
*
::before
:disabled
:root
::after
::-webkit-scrollbar-thumb
::-webkit-scrollbar
.fileText .file-info a:has(> .fnswitch)
.globalMessage *
.catalog-post .postlnfo *
.pagelist .pages:not(.cataloglink) *
.catalog-post [class^="qmark"]
.fileText a
.file:hover .fileText
:root:not(.bottom-backlinks) .container.not(:empty)::before
#fourchanx-settings legend + *
.postNum > a:first-child
.catalog-post > .postInfo > :not(.subject):not(.nameBlock):not(.dateTime)
#qr .oekaki-bg > *
.stub ~ :not(.threadDivider)

Keep it mind this is with 4x CPU throttling, but faster CSS is faster CSS regardless of throttle.

Also to keep in mind is this appears to only really happen in threads with over 150 replies.

saxamaphone69 commented 1 year ago

In a 250 post thread,

Using

.stub + .replacedSideArrows,
.stub + .replacedSideArrows + .post
    display none

takes it under 2500µs.

The original CSS

/* .stub ~ * is probably a little too expensive $$$ - but it's there because
 if json index is off and replies are shown, it covers all bases */
.stub ~ *
    display none

takes 21000µs.

Is the 0.02 seconds (which is 4x slower than normal) in savings worth it?

saxamaphone69 commented 1 year ago
:where(b, strong, th, legend, .subject, .name)

In a 400 post thread, 13500µs with 13106 match attempts but only 400 found.

Without :where(), as in just b, strong, th, legend, .subject, .name pings once for the single .subject on the page, and 205µs for .name, with 404 counts for 404 attempts.

saxamaphone69 commented 1 year ago

Also, some of those selectors are the original 4chan X CSS that loads, renders, then gets removed.

saxamaphone69 commented 1 year ago

Using the free version of Project Wallace:

image

image

image

image

Though I'm sure the paid version would tell me which of these are more complex. I also am writing in .styl so I don't see the CSS.

image

saxamaphone69 commented 1 year ago

https://jonassebastianohlsson.com/specificity-graph/ https://csswizardry.com/2014/10/the-specificity-graph/ image

saxamaphone69 commented 1 year ago

Using https://isellsoap.github.io/specificity-visualizer/ I had to remove :has() that started with > or +, so for example :has(> .fnswitch) and :has(+ .poster-mod).

image

image

A lot of them are red because of poor naming conventions on 4chan X's side and are out of my control (inconsistent naming, lack of generic classes).

image

Some of them are probably my fault.

saxamaphone69 commented 1 month ago

image

image

image

image