Skip to content

Don't inline the layout algorithm entry points - #1339

Open
nicoburns wants to merge 1 commit into
mainfrom
devin/1792423004-inline-never-entrypoints
Open

nicoburns wants to merge 1 commit into
mainfrom
devin/1792423004-inline-never-entrypoints

Conversation

@nicoburns

@nicoburns nicoburns commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Objective

Give the layout recursion a non-inlined boundary below the cache, at the algorithms themselves: #[inline(never)] on compute_flexbox_layout, compute_grid_layout and compute_block_layout.

Without it, LLVM may inline an algorithm into the function that dispatches on display mode (each algorithm usually has a single call site per tree type). That function's frame is then reserved at the size of the largest inlined algorithm at every level of nesting, whichever algorithm the node actually uses. With fat LTO on main, TaffyTree's dispatch closure has flexbox inlined into it (1728 B frame, vs 240 B in a default release build), so a chain of nested block containers pays for flexbox's frame at every level.

Because the attribute is on the generic entry points, it applies to every tree implementation, not just TaffyTree.

No CHANGELOG entry: there is no API or behaviour change.

Context

Split out of the review of #1338, which puts the boundary above the cache (on TaffyView::compute_child_layout). This PR does not include that change and is independent of it.

All measurements are on e82f526, rustc 1.99, x86-64 Linux.

Stack per level of nesting (bytes, 1000-deep chain of one container type; deepest stack pointer seen in the leaf measure function, divided by the depth):

profile chain main this PR change
default release flex 3042 3042 0
default release block 2802 2802 0
default release grid 5106 5106 0
lto = "fat", codegen-units = 1 flex 2707 3394 +25%
lto = "fat", codegen-units = 1 block 4883 3602 −26%
lto = "fat", codegen-units = 1 grid 7187 5906 −18%

In a default release build this is a no-op: LLVM already keeps the algorithms out of line.

Instructions vs main (callgrind, layout only):

workload default release fat LTO
flex, 4 levels × 10 0.0% −0.3%
flex, 100 × 100 0.0% −0.1%
flex chain, 1000 deep 0.0% −2.8%
grid, 4 levels × 10 0.0% +0.2%
block, 4 levels × 10 0.0% +0.4%
flex relayout 0.0% −0.2%

Wall time vs main (Criterion, target-cpu=x86-64-v2, 10 rounds interleaved per benchmark on one pinned core; min of rounds, then median of per-round ratios with its range; "spread" is max/min of main across rounds):

bench default profile main spread fat LTO main spread
flexbox Wide tree 10000 0.0% / −0.1% [−4,+3] 1.04× +0.1% / −0.7% [−5,+7] 1.07×
flexbox Deep tree (auto size) 10000 +0.2% / +0.3% [−5,+2] 1.06× −1.0% / −1.2% [−6,+3] 1.08×
flexbox Deep tree (random size) 10000 −0.1% / −0.7% [−4,+2] 1.05× −1.4% / −3.2% [−9,+2] 1.12×
flexbox super deep 100 +0.2% / +0.8% [−4,+5] 1.05× −0.3% / +1.5% [−7,+27] 1.17×
flexbox yoga 'huge nested' 10000 +0.1% / +0.4% [−4,+2] 1.05× −0.7% / −0.9% [−12,+3] 1.36×
PanGUI fit_nesting −1.6% / +0.8% [−8,+19] 1.24× +2.6% / +1.9% [−14,+5] 1.25×
PanGUI wide_wrapping −0.4% / 0.0% [−3,+1] 1.05× +5.3% / +5.6% [+4,+8] 1.05×
PanGUI nested_vertical_stack +0.8% / −0.3% [−2,+5] 1.07× +5.0% / +5.4% [+4,+7] 1.03×
PanGUI flex_expand_weights −0.1% / 0.0% [−4,+6] 1.09× −0.5% / −1.3% [−4,+3] 1.06×
relayout balanced flex +0.3% / +0.1% [−5,+7] 1.10× −1.4% / −0.4% [−6,+26] 1.30×
relayout balanced block 0.0% / −0.4% [−6,+5] 1.11× −2.2% / −1.6% [−36,+22] 1.56×
relayout balanced grid −0.1% / −1.9% [−7,+8] 1.09× −0.6% / −0.2% [−7,+2] 1.26×
relayout resize flex −0.2% / +0.5% [−6,+5] 1.06× +2.0% / +1.9% [−5,+9] 2.11×
relayout resize block −0.4% / −0.8% [−8,+14] 1.11× +0.3% / −2.3% [−8,+8] 1.96×
relayout deep mixed −0.2% / −0.2% [−5,+6] 1.05× −0.5% / 0.0% [−5,+52] 1.34×
grid wide 100x100 −1.7% / −1.7% [−5,+4] 1.05× −1.3% / −0.7% [−12,+3] 1.50×
grid deep 3x3 +0.2% / +0.6% [−4,+7] 1.09× −0.8% / −1.7% [−22,+2] 1.27×
grid deep 2x2 16384 0.0% / −0.8% [−7,+6] 1.08× −0.9% / +0.2% [−2,+6] 1.11×
grid superdeep 1000 +0.5% / −0.6% [−4,+2] 1.07× −1.2% / +0.5% [−3,+2] 1.11×

Default profile: within noise of main everywhere. Fat LTO: within noise except PanGUI/wide_wrapping and PanGUI/nested_vertical_stack, which are about 5% slower in every round. The fat LTO run was noisier than the default one (see the spread column), so its other rows are weaker evidence.

Feedback wanted

Under fat LTO this is a trade rather than a pure win:

  • A flex-only chain uses 25% more stack per level than on main, while block and grid chains use 18–26% less. On main flexbox is merged into the dispatch frame, so a flex level has one frame where this PR gives it two; I have not confirmed that this is the whole cause.
  • Two PanGUI benchmarks are about 5% slower. Not root-caused.

Combined with #1338's attribute, the fat LTO stack numbers are 2561 / 3169 / 5121 (below main on all three chains), but that attribute costs 3–16% wall time on flex benchmarks in a default build.

Link to Devin session: https://dioxus.staging.devinenterprise.com/sessions/259d4169660a4e578f212fee440f9eea
Open in Devin Desktop: https://dioxus.staging.devinenterprise.com/desktop/session/259d4169660a4e578f212fee440f9eea?variant=devin-insiders
Requested by: @nicoburns

@staging-devin-ai-integration

Copy link
Copy Markdown

I'll fix CI failures and address comments from users with write access that start with 'Devin'.

  • Disable automatic comment, CI, and merge conflict monitoring

This branch has not been deployed

No deployments
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