Skip to content

Skip the layout cache for context-free leaves - #1377

Open
nicoburns wants to merge 1 commit into
mainfrom
cheap-leaf-cache-bypass
Open

nicoburns wants to merge 1 commit into
mainfrom
cheap-leaf-cache-bypass

Conversation

@nicoburns

Copy link
Copy Markdown
Member

Objective

Skip the layout cache for childless, context-free, visible nodes in TaffyTree. These leaves are cheaper to recompute than to look up and store: a cache probe, a key build and a store cost more than the leaf algorithm itself. The idea comes from cephal, which handles such "cheap leaves" before the cache lookup.

Changes

  • TaffyView::compute_child_layout calls measure_function directly for these nodes. There is no cache lookup or store, and no OOF pass (a leaf has no hoisted children).
  • NodeData::has_uncached_layout keeps dirty() accurate for these nodes: clean after layout, dirty after mark_dirty/set_style/a hidden layout.
  • mark_dirty always continues to the starting node's parent. Its AlreadyEmpty early exit now applies only to ancestors, because a bypassed leaf's cache is always empty.
  • Tests cover the bypass, leaves with a context (still cached), hidden leaves, and parent invalidation after a leaf's style changes.

Benchmarks

Alternating main/branch runs, 3 each, pinned to one core, --measurement-time 3, on a VM (up to ~1.8% CPU steal). Median of the three Criterion estimates:

Benchmark main branch change
grid wide 100x100 5.950 ms 5.674 ms -4.6%
grid wide 31x31 495.8 µs 460.8 µs -7.1%
flexbox wide 2-level 8.067 ms 7.770 ms -3.7%
PanGUI fit_nesting 63.41 ms 61.23 ms -3.4%
flexbox deep auto 14-level 15.14 ms 15.52 ms +2.5%

Feedback wanted

  • A custom measure function passed to compute_layout_with_measure is now called on every query for context-free leaves, instead of having its result cached. That's fine for the usual "no context → zero size" functions, but it is a behaviour change for anyone doing real work there. Should it get a CHANGELOG note, or should the bypass be limited to compute_layout (the built-in measure)?
  • The gains are modest (3–7%). Most of the cache overhead in the profiles is on containers, not leaves.

Link to Devin session: https://dioxus.staging.devinenterprise.com/sessions/590d5c946bbe49cebc90460f69dd0bd3
Open in Devin Desktop: https://dioxus.staging.devinenterprise.com/desktop/session/590d5c946bbe49cebc90460f69dd0bd3?variant=devin-insiders

@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