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
[css-grid-3] intrinsic track sizing algorithm for masonry can go exponential in complexity. #10053
Comments
Exponential in what? The subgrid nesting level? If so, it it really such a bad thing? Do deeply nested subgrids with masonry have compelling use cases? |
Discussed with the Apple/WebKit team... We agree that subgridded masonry within masonry can create an exponential calculation. However this only affects intrinsic track sizing, so the dangers here are limited to: intrinsically sized masonry tracks combined with multiple levels of subgridded masonry nesting combined with large numbers of tracks. We don't think the cases where these calculations become unmanageable will be common:
To address the "but what if concerns", we're OK with introducing a UA-defined limit on e.g. the depth of masonry subgrid items that can contribute sizing back up to the master grid. A limit like this can prevent exponential explosion, while still allowing
|
I really think that spanning items should not contribute to the width of the columns in masonry. Even in a regular grid, this is the behavior that I find unnecessary and often harmful, and I don't think there are many legit use cases for wanting this in a masonry layout. As an author, when I want some element to span other columns/rows, I want it to adapt to whatever there is, not to contribute. (copying this part from #9041 (comment)) When some |
I disagree. Like, if you have |
In my practice, I never encountered use cases for this. Usually, to be resilient, elements tend to have a small min-content, adapting in one way or another to the context. Even the opposite: numerous times I had to give these spanning items While I think it could be useful to have a control over if any particular spanning item contributes its min-content to the columns for regular grids, I am not talking about changing how it works now, but about a compromise that will enable masonry-type grids with spanning items. I will always take this limitation compared to the absence of a feature completely. |
As we outlined over in #9041 (comment), spanning items and intrinsic tracks are totally fine perf-wise, if all the tracks are the same intrinsic size. (And spanning items across fixed/flexible tracks aren't problematic at all.) It's just when you mix an intrinsic track with some different-sized tracks (intrinsic or not) that you run into these issues. And so far, we haven't seen any example of Masonry grids that want to exceed that limitation - if they want intrinsic sizes, they want them all the same; if they want different sizes, they want fixed/flexible sizes, rather than intrinsic ones. So we should be just fine handling spanning items properly. |
https://drafts.csswg.org/css-grid-3/#track-sizing
Currently you need to place everything in every possible position. With subgrid this means that the complexity can go ~exponential (or sub-exponential).
In the above example there are 60 positions you need to test (each subgrid level might have different margin/border/padding which needs to be taken into account for the items contribution in a particular position along with many other factors).
In Blink we've spent most of our performance work in layout fixing exponential time bugs - developers really care about layout time performance. While these issues were quality of implementation bugs (and not a core problem with a particular spec), having exponential time complexity in a spec seems bad[1].
[1] - Exponential time complexity doesn't care how powerful your CPU is - it'll always win.
The text was updated successfully, but these errors were encountered: