2 ms·
One thing that would be interesting to see is how a complex webpage performs without the limitations CSS places to allow fast styling computation. E.g. in regar
by zamadatix 4y ago
One thing that would be interesting to see is how a complex webpage performs without the limitations CSS places to allow fast styling computation. E.g. in regards to this article there is no explicit "if" in CSS because allowing generic comparisons instead of specific ones related to elements and parent/children elements would break core assumptions styling engines get to use to handle CSS at lightning speed. At the same time I wonder if having all these limitations is part of why auto-generated sites have ridiculous amounts of elements, attributes, and styling to parse in the first place.
- marcosdumay 4y agoCSS doesn't have explicit "if" because it's a logical language, and thus every single thing you write is an "if". The only things missing from it having universal logic are coming with the ":has" selector. So there isn't anything to argue about performance. The new ":has" is a performance killer, everybody knows it, nobody really cares because it's only a problem if you abuse it... and of course people will make a point of abusing it. Interestingly, it is also getting predicate composition, with hierarchical selectors. Looks like the CSS people finally decided to turn it into a usable logic language. The auto generated sites have huge amounts of them because both auto generated code tends to be bad, and because it lacks composition. One of those is being solved.
- zamadatix 4y agoThere are definitely selectors that have more of a performance impact than others but they still don't allow you to break some general assumptions. E.g. taking :has() the addition is styling an element base on a relative selector anchored to that element but it doesn't allow for arbitrarily anchored selectors or matching things which could result in cycles. A lot of what browser engines did to make that work reasonably fast like here https://twitter.com/anttikoivisto/status/1473251189181591554 https://twitter.com/anttikoivisto/status/1473251189181591554 might not work efficiently with something less restrictive such as a true general purpose if(). I'm not familiar with what you're referring to with hierarchical selectors. CSS combinators have always let you select different types of decedents and :has() lets you select either way. Are you referring to Cascade Layers, or maybe something else?