-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize DOM selector lookups by pre-warming by selectors' parents #296
Conversation
I used this page to test things: https://www.peterbe.com/plog-original.html It uses Semantic-UI which is horribly verbose! (Hint view source and look at the CSS) 183c183,185
< * {
---
> *,
> :after,
> :before {
196,197d197
< height: 100%;
< font-size: 14px;
203,206d202
< body,
< h1 {
< padding: 0;
< }
208a205,206
> margin: 0.67em 0;
> line-height: 1.28571429em;
210a209
> padding: 0;
213,214d211
< margin: 0.67em 0;
< line-height: 1.28571429em;
231c228,233
< body {
---
> ::-webkit-file-upload-button {
> -webkit-appearance: button;
> font: inherit;
> }
> body,
> html {
232a235,239
> }
> html {
> font-size: 14px;
> }
> body {
233a241
> padding: 0;
259a268,279
> ::-webkit-selection {
> background-color: #cce2ff;
> color: rgba(0, 0, 0, 0.87);
> }
> ::-moz-selection {
> background-color: #cce2ff;
> color: rgba(0, 0, 0, 0.87);
> }
> ::selection {
> background-color: #cce2ff;
> color: rgba(0, 0, 0, 0.87);
> } (red means output with Here's the master.css and branch.css outputs prettierfied. I'm pretty sure this is correct fix. Things like Semantic-UI does like... *, :before, :after {
-webkit-box-sizing:inherit;box-sizing:inherit
} should not be deleted from the final CSS. (not that I understand the CSS itself) |
In terms of speed... Before:
After:
That means, on median the total processing time goes from 6.3s to 5.1s. |
@stereobooster This one is quite complex but I think it's valuable. Not expecting a deep code review but if you could take a look I'd appreciate it. Thanks in advance. |
// This is the protection against ever looking up the same CSS selector | ||
// more than once. We can confidently pre-populate it with a couple that | ||
// we're confident about. | ||
const decisionsCache = { '*': true, body: true, html: true, '': true }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What empty string selector ''
stands for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You know, I'm actually not sure.
If you look at view-source:https://www.peterbe.com/static/css/base.min.79787297dbf5.css (which comes from https://github.com/peterbe/django-peterbecom/blob/master/peterbecom/base/static/css/semantic/reset.min.css) you see this:
*,:after,:before{-webkit-box-sizing:inherit;box-sizing:inherit}
And if you remove the pseudo stuff all you're left with is ''
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess there is an error where we convert AST to selectors, it should be :after
instead of ``. Or at least we can add comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it comes from reduceCSSSelector
. In terms of CSS selector and DOM inspecting the thing to look for is before the :
. But if the whole CSS selector is :after { ... }
then his is what happens.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add small explanation why there is empty string, so we don't forget
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bummer! I forgot this before I merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done d16f2c1
Co-Authored-By: peterbe <peterbe@mozilla.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🥇
Thank you @stereobooster ! It still saddens me that it takes ~5 seconds to execute against these monster CSS files. The blame lies with Semantic-UI for being so overly verbose in its style. |
By the way, for So 3,285 |
Part of #287