Repository navigation
Conversation
6 tasks
This was referenced Nov 10, 2026
…d_layout` The min-content block size of a box is its max-content block size (css-sizing-3 §5.1), so layouts with either available height give the same result. Map the height constraint once at the entry point of every cached layout, so that both queries share one cache entry and the child is laid out once.
YeungKC
force-pushed
the
perf/min-content-block-size
branch
from
November 23, 2026 06:45
fc973c7 to
65a3ba7
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Objective
Fixes #1403
Lay out a child once instead of twice when the only difference between two queries for it is whether its available height is
MinContentorMaxContent.The min-content block size of a box is its max-content block size (css-sizing-3 §5.1), so the two queries always give the same result. The layout cache keys them separately. In nested flex and grid trees, many children get both queries, and each runs the full layout of the child's subtree.
Context
#1284 applies the same rule in grid track sizing, for the expansion of flexible tracks. This PR applies it once, at the entry point of every cached layout:
The width axis does not change. There, min-content and max-content are different constraints.
Cache misses for one fresh layout of a 2047-node flex tree (alternating row and column, auto sizes), grouped by input shape. Each pair differs only in the available height:
Tests
cargo test --all-featurespasses. All generated Chrome fixtures pass with no changed expectation.tests/hand_written/caching.rsassert measure-function call counts. The counts go down:measure_count_nested_gridmeasure_count_grid_item_with_known_widthmeasure_count_grid_item_in_fixed_trackmeasure_count_flex_in_grid(row / column)Performance
Criterion,
cargo bench -- --baseline main, on Apple Silicon. An A/A run ofmainagainst the same baseline drifts by −1% to +4%.mainrelayout/deep/flex/8191relayout/balanced/flex/11111mixed_flex_grid/mixed/depth_4_width_4mixed_flex_grid/mixed/depth_4_width_8PanGUI/fit_nestingmixed_flex_grid/mixed/depth_2_width_4relayout/deep/mixed/8191grid/deep/2x2/1024grid/deep/3x3/6561grid/superdeep/1x1/1000relayout/wide/grid/10101Most other benchmarks stay within the A/A drift. The
flexboxbenchmarks (fresh layout of trees with mostly definite sizes) are about 1% slower than in the A/A run. Three smallPanGUIflex benchmarks are +5% to +6%, about 2% above the A/A range:padding_and_margin,wide_no_wrap_simple_fewandwide_wrapping. These trees have no duplicate queries to remove, so they only pay for the extra comparison.Feedback wanted
Measure functions and custom layout algorithms called through
compute_cached_layoutno longer receiveAvailableSpace::MinContentin the height axis; they receiveMaxContent. The built-in algorithms give the same result for both, and the Chrome fixtures confirm this. A measure function that returns a different height for the two constraints would change behavior. I documented this in theCHANGELOG.mdentry.An alternative is to stop producing a min-content height at each source, like Blink does:
GridLayoutAlgorithmreturnsBlockContributionSize()for both the min-content and the max-content contribution in the block axis. In Taffy, a min-content height comes from several places:GridItem::min_content_contribution, the flex basis and automatic minimum size measurements,block.rs, themin-contentsizing keyword, containers that pass their own available height on to their children, and the caller ofcompute_layout. A fix at each source would need to cover all of them, and custom algorithms would still create the duplicates. That is why I chose the entry point. Is this acceptable, or would you prefer the fix at the sources?