Skip to content

Measure both axes so width-only measurements are safe to cache - #619

Open
maurerdietmar wants to merge 1 commit into
DioxusLabs:mainfrom
maurerdietmar:width-only-measure-cache
Open

Measure both axes so width-only measurements are safe to cache#619
maurerdietmar wants to merge 1 commit into
DioxusLabs:mainfrom
maurerdietmar:width-only-measure-cache

Conversation

@maurerdietmar

@maurerdietmar maurerdietmar commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Asking a box only for its width, when its width is already known, gets a height of zero back: taffy's block layout short-circuits, because the caller said it did not want the height. The measurement cache keys on the known dimensions and treats the requested axis as irrelevant, so that answer is stored where a later height query for the same box finds it, and the box reports no content at all.

Table cells are laid out at the width of their column, which is what makes them ask for this. A row then falls back to whatever height is specified elsewhere in it: a data table row carrying a spacer cell of height: 22px came out 22 tall around a 30px cell, clipping the text against the bottom of every row, and a row with no specified height anywhere collapsed onto its padding.

Answer width-only requests from the cache when a full measurement is already there, and otherwise measure without storing the result. The height a later query needs is computed once either way, so this trades no work for the correct answer.

WPT results

22 newly passing, 8 newly failing (net +14).

Full diff (30 changed tests)
+ Fail => Pass css/CSS2/backgrounds/background-position-applies-to-013d.xht
- Pass => Fail css/CSS2/margin-padding-clear/margin-collapse-101.xht
- Pass => Fail css/CSS2/margin-padding-clear/margin-collapse-105.xht
- Pass => Fail css/CSS2/margin-padding-clear/margin-collapse-113.xht
- Pass => Fail css/CSS2/margin-padding-clear/margin-collapse-115.xht
+ Fail => Pass css/CSS2/tables/fixed-table-layout-003b01.xht
+ Fail => Pass css/CSS2/tables/fixed-table-layout-003b02.xht
+ Fail => Pass css/CSS2/tables/fixed-table-layout-003b03.xht
+ Fail => Pass css/CSS2/tables/fixed-table-layout-003b04.xht
+ Fail => Pass css/CSS2/tables/fixed-table-layout-003b05.xht
+ Fail => Pass css/CSS2/tables/fixed-table-layout-003b06.xht
+ Fail => Pass css/CSS2/tables/fixed-table-layout-003b07.xht
+ Fail => Pass css/CSS2/tables/fixed-table-layout-003b08.xht
+ Fail => Pass css/CSS2/tables/fixed-table-layout-003b09.xht
+ Fail => Pass css/CSS2/tables/fixed-table-layout-003b10.xht
+ Fail => Pass css/CSS2/tables/fixed-table-layout-003b11.xht
+ Fail => Pass css/CSS2/tables/fixed-table-layout-003b12.xht
+ Fail => Pass css/CSS2/tables/fixed-table-layout-003c01.xht
+ Fail => Pass css/CSS2/tables/fixed-table-layout-003c02.xht
+ Fail => Pass css/CSS2/tables/fixed-table-layout-003c03.xht
+ Fail => Pass css/CSS2/tables/fixed-table-layout-003c04.xht
+ Fail => Pass css/CSS2/tables/fixed-table-layout-003c05.xht
+ Fail => Pass css/CSS2/tables/fixed-table-layout-003c06.xht
+ Fail => Pass css/CSS2/tables/fixed-table-layout-003c07.xht
+ Fail => Pass css/CSS2/tables/fixed-table-layout-003c08.xht
- Pass => Fail css/css-flexbox/flex-aspect-ratio-img-column-011.html
- Pass => Fail css/css-flexbox/flex-aspect-ratio-img-row-007.html
- Pass => Fail css/css-flexbox/flex-aspect-ratio-img-row-017.html
- Pass => Fail css/css-flexbox/flexbox-min-width-auto-002b.html
+ Fail => Pass css/css-grid/layout-algorithm/grid-find-fr-size-gutters-001.html

Generated by the WPT workflow.

@maurerdietmar
maurerdietmar force-pushed the width-only-measure-cache branch from c67a466 to 41f081a Compare August 8, 2026 07:47
Asking a box only for its width, when its width is already known, gets a
height of zero back: taffy's block layout short-circuits, because the
caller said it did not want the height. The measurement cache keys on the
known dimensions and treats the requested axis as irrelevant, so that
answer is stored where a later height query for the same box finds it,
and the box reports no content at all.

Table cells are laid out at the width of their column, which is what
makes them ask for this. A row then falls back to whatever height is
specified elsewhere in it: a data table row carrying a spacer cell of
`height: 22px` came out 22 tall around a 30px cell, clipping the text
against the bottom of every row, and a row with no specified height
anywhere collapsed onto its padding.

An earlier revision of this fix kept width-only answers out of the cache
instead. That traded the wrong answer for recomputation: every width
probe a flex or block parent issues laid its subtree out again, and a
page nested a few flex and scroll containers deep re-shaped its text
dozens of times over in a single pass - a 33x difference in inline
layout work for the same content, and seconds of delay when a form-heavy
view appeared.

Upgrade width-only size requests to both axes before they reach the
layout algorithms instead. The height at the resolved width is computed
once per cache key, every stored entry answers any axis, and repeated
probes hit the cache. The zero-height short-circuits in the algorithms
become dead paths rather than cache poison.

Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
@maurerdietmar
maurerdietmar force-pushed the width-only-measure-cache branch from 41f081a to 3ebb2d4 Compare August 8, 2026 07:57
@maurerdietmar maurerdietmar changed the title Keep width-only measurements out of the layout cache Measure both axes so width-only measurements are safe to cache Aug 8, 2026
@maurerdietmar

Copy link
Copy Markdown
Contributor Author

Reworked: instead of keeping width-only answers out of the cache, width-only requests are upgraded to both axes so every cached entry is complete — the exclusion made every width probe re-lay-out its subtree, which we measured as a 33x inline-layout overhead on deeply nested pages.

Tests unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant