3 ms·
> It's impossible to optimize CSS, for example. That's a bold claim, and it does not square with my experience optimizing CSS implementations. In fact, CSS at
by pcwalton 11y ago
> It's impossible to optimize CSS, for example.
That's a bold claim, and it does not square with my experience optimizing CSS implementations. In fact, CSS at its core is well suited for parallel implementations, saturating all CPUs on typical workloads, and its declarative rendering structure maps more naturally to hardware-accelerated graphics APIs than traditional vector graphics APIs do.
Why, specifically, do you think CSS is unoptimizable?
- striking 11y agoCSS is an imprecise language that targets indiscriminately and is difficult to statically analyze. But I'll admit that I was wrong about it being totally impossible to optimize. The fact that it's declarative makes it at least multithreaded. Also, shadow DOM and web components may even fix my disagreements with it anyway.
- pcwalton 11y ago> CSS is an imprecise language that targets indiscriminately and is difficult to statically analyze CSS as specified is imprecise, yes, but individual browser implementations implement their own precise behaviors. (This is no worse than native UIs.) CSS has a lot of weird quirks, but techniques such as Gecko's display lists have gone a long way toward taming this complexity by lowering to a simpler form. This opens up aggressive optimizations at the engine level (which is not to say that browser engines are currently doing all optimizations that are possible!) What's nice about CSS in terms of analysis is, again, its declarative nature: the fact that common layouts are implemented declaratively means that browser engines have a lot of freedom to optimize them in different ways.
- cwzwarich 11y agoAs somebody who has optimized both CSS implementations and native rendering engines / UI frameworks, the main reason why I am fundamentally skeptical about the performance of CSS as an application platform is incremental layout. No one has ever implemented CSS with incremental layout in a way that is even close to being competitive with native UI code. If you want to make a responsive UI, doing work incrementally and amortizing the cost of actions across frame intervals is more important than raw performance. This is especially true on mobile, where frequency / voltage controllers for CPUs and GPUs are tuned to work best on consistent workloads rather than bursty workloads.
- pcwalton 11y ago> No one has ever implemented CSS with incremental layout in a way that is even close to being competitive with native UI code. So this is a really broad statement and without further clarification it's hard to pin down precisely what you mean. By incremental layout do you mean partial layout, or relayout after dynamic changes? For the latter, I don't see how flexbox (for example) is worse in this area than springs and struts, as it essentially is springs and struts. And for absolutely positioned UIs (the old way mobile apps were laid out), layout time of CSS is essentially zero. For the former, it's commonplace to use frameworks that will do the standard "UITableView" sort of optimizations in script. Moreover, though, there's CSS Containment [1] coming soon to allow for these sorts of optimizations without having to use JS. I agree that CSS Containment is critical to allow CSS to achieve the performance of native frameworks, but this is an area of active work, and I don't see any roadblocks in the way of partial layout once CSS Containment arrives. [1]: https://drafts.csswg.org/css-containment/ https://drafts.csswg.org/css-containment/