News for hackers. Stuff that matters.
Re:CSS Containment Specification by hinkley on Saturday February 15, 2020 @11:49PM (#22339847)
I worked on a mobile web browser what seems like ages ago. The previous maintainer was recalculating the layout on every scroll operation, and then rendering the entire thing. It was, uh, slow.

The first thing I did was rip out the layout engine and give everything on the page extents at load time. Eventually, scrolling involved finding the range that fell within the viewport and rendering that. That seemed like what any video game designer would do for a side scroller. I just turned it 90°. Ended up about as fast as Openwave and much smaller.

This article sounds as if CSS3 browsers don’t or can’t do that. I find that quite surprising. Unless we’re using a different definition of render (I still had to lay everything out).

Re:CSS Containment Specification by frivoal on Sunday February 16, 2020 @12:40AM (#22339989)
Browsers can do that, scrolling is cheap (unless you highjack it with JS, but that's another story).

However, if change the layout / content of some element in the page, making it bigger, or smaller, or positioned differently, etc, that has an impact on its parents, recursively. So browsers mark subtrees as dirty when something changes, and work their way back up.

In certain cases, there are changes that cannot have an effect on the parents, so you should be able to stop the recursion. And browsers typically are reasonably smart about that.

However, there are a surprisingly large number of cases where checking whether or not the parents could possibly be affected by the change is an expensive operation, so you're better off relaying out your parents (recursively) rather than checking if you could safely skip doing it.

Css-contain changes the rules of how css works, to eliminate these expensive to check cases. contain:content makes a few useful things impossible. contain:strict is even harsher, as parents' size cannot depend on children's size. But if you happen to have an element that can be set up to fit within these constraints, turning containment on on the right element lets the browser know that a whole bunch of optimizations are safe without checking for preconditions.

Re:CSS Containment Specification by _bxg1 on Sunday February 16, 2020 @02:24AM (#22340347)
Modern browsers only re-render sections of the page as necessary, and don't re-render at all as you scroll (they just move that static image up and down). This API is for cases where the actual DOM and/or styles change. If that isn't happening, there's no use for it.