Skip to content

perf: deferred Yoga layout-cache follow-ups (skip-clean-children, cached min-content, Reset dead-code) + cross-axis measure-cache staleness #681

Closed

Description

Follow-up tracking for Yoga layout-engine work intentionally deferred from #658 / #670 (the layout-cache-guards + inline-per-node-arrays perf PR). Filing so the deferred items and one residual correctness gap surfaced by the pre-GO audit aren't lost. Scope: src/Reactor/Yoga/ only.

Deferred perf optimizations (each: why deferred / what it'd take)

Residual correctness gap surfaced by the pre-GO stale-state audit (please triage)

Flagged as correctness, not just perf — included here for traceability but may warrant its own priority/label.

Cross-axis measure-cache staleness after the #138 setter guards. The #138 equality guards + FlexPanel no longer re-dirtying every child each MeasureOverride correctly enable the layout cache, but they remove the implicit per-frame refresh that used to keep measure-backed leaves fresh. The #140 ComputeMinContent probe re-dirties a leaf only on a MAIN-axis min-content change — ResolveMinDimension returns Undefined for the cross axis (no probe). So a content change that alters a flex child's cross-axis size (e.g. wrapping-text height when the longest word is unchanged), or the size of a flex-basis:0 / explicit-min child, without changing main-axis min-content, leaves the Yoga leaf clean → the input-keyed measurement cache (CachedLayout/CachedMeasurements) serves a stale size. Pre-#138, the accidental per-frame re-dirty masked this. Same risk class as the already-fixed ComputedFlexBasis regression (#670), but for the measure cache rather than the resolved basis.

Exposure: narrow but real and non-self-correcting — flex items with multi-line/wrapping text whose height changes from content updates, or content-driven cross-axis sizing under basis:0/explicit-min. Common single-line cases (grid cells, labels, numbers) stay correct because their main-axis min-content tracks the change.

Candidate fixes: (a) host/reconciler → YogaNode.MarkDirty bridge when measure-backed child content changes — the faithful Yoga contract; cross-cutting (Core/Reconciler + a FlexPanel notify API), preserves the perf win. (b) FlexPanel-local: re-measure each measure-leaf at its last-resolved constraint and compare, dirtying on change — fully correct but adds a measure/child/pass (perf-sensitive, wobble/LayoutCycleException care needed). (c) Probe both axes in ComputeMinContent — changes CSS cross-axis-min semantics, not acceptable as-is.

A repro selftest (mutate a wrapping-text flex child's content without touching its Yoga style; assert the panel height updates) would pin this; the fixture lives outside src/Reactor/Yoga/.

Refs: #658, #670. Exposed by the #138 setter-equality guards.

Activity

  1. azchohfi commented on Jun 29, 2026

    @azchohfi
    CollaboratorAuthor

    Resolved — all sub-items dispositioned (follow-up to #665/#670 Yoga work).

    Done:

    Deferred / won't-fix (with rationale):

    Closing. The inline-ThemeBinding[] idea (#683 Item A) is tracked separately as deferred (cross-cuts the actively-edited reconciler; unproven value).

  2. azchohfi commented on Jun 29, 2026

    @azchohfi
    CollaboratorAuthor

    Consolidated findings — Yoga layout-cache follow-ups (canonical revisit-ticket for the deferred bundle)

    Dispositions for the three items named in this issue's title, plus the deferred-bundle revisit plan.

    1. Cross-axis measure-cache staleness — RESOLVED-WITH-GUARDS ✅

    Investigated repro-first. It does not reproduce on current main — it was a side-effect of the former #138 setter equality-guards, which PR #740 reverted to unconditional dirty. FlexPanel.SyncYogaTree now re-dirties every child node every MeasureOverride (via the Display / MinWidth / Margin setters), and a dirty node clears Yoga's constraint-keyed measurement cache (the needToVisitNode reset in YogaAlgorithm). So a content change that grows a flex child's cross-axis size re-flows the panel even when the main-axis min-content (longest word) is unchanged. Notable: #138 was both a −39.6% Flex-rps perf regressor AND the cause of this correctness staleness — #740 fixed both.

    Regression guards shipped in #747 (tests-only, no production change):

    • YogaMeasureCacheStalenessTests (headless) — engine contract + a negative control proving the constraint-keyed cache serves a stale size without a dirty.
    • CrossAxisMeasureStalenessFixture (selftest) — end-to-end: a wrapping TextBlock whose line count grows (longest word unchanged) re-flows the panel (verified 19→131px tracking 18.6→130.3px child growth).

    2. LayoutResults.Reset() dead-code (#146) — DONE ✅

    Removed in #745 (zero production callers; lone unit test removed with it; Release build 0/0 proves no callers).

    3. skip-clean-children (#139) + cached-min-content (#140) — WONTFIX-WITH-FINDING ⛔

    Correctness-by-construction: ComputeMinContent's per-leaf Measure(0,∞) is currently the only mechanism that dirties a measure-backed leaf on a main-axis content change; the per-pass ApplyAttachedProperties push is the only freshness signal for measure-backed leaves. A Yoga-local cache/skip of either drops that per-pass re-dirty → reintroduces the main-axis analog of the cross-axis staleness that #747 guards against (the same #742-class regression). There is no correct Yoga-local variant; a correct version needs a cross-cutting host → reconciler → YogaNode.MarkDirty bridge (Reconciler-owned) — the same bridge that gates the inline-ThemeBinding[] item below.

    Ceiling A/B (throwaway optimistic-cache on StressPerf.Flex, correctness aside, never shipped) — median of 3 reps each, percent=50, duration=10s, judged on the Flex leg's allocation surface + Renders/sec (not reconcile/diff ms):

    Metric main optimistic ceiling Δ
    Renders/sec 2.58 2.98 +15.5%
    alloc-bytes/render 7.74 MB 7.74 MB ~0% (neutral)
    Gen0 / KRenders 1370 1387 ~0% (noise)

    Reading: the rps gain is real (non-overlapping bands) but alloc/Gen0 are flat — ComputeMinContent is CPU, not allocation. So even the over-optimistic upper bound (which over-skips Width/Margin changes and ignores the staleness correctness) fails the ship bar of "rps-better AND alloc-improvement", and the realized correct gain would be ≤ +15.5% rps / ~0% alloc. This is also a synthetic worst-case (≈2000 fully-realized, non-virtualized leaves, full child-tree rebuild every frame); real virtualized apps would see materially less. Business case for the bridge: a capped, alloc-neutral rps prize on a worst-case macro — not worth the cross-cutting Reconciler complexity + #742-class correctness risk on its own.

    4. Inline ThemeBinding[] (#167, from #683) — DEFERRED, bundled here

    Deferred: it ripples into ApplyThemeBindings / BuildCacheKey across Reconciler.cs / Reconciler.Mount.cs / Reconciler.Update.cs (actively edited by the Reconciler-core work), and its value is unproven (an inline-array alloc opt with no theme-binding-heavy /perf workload). Revisit after the Reconciler-core PRs land, routing the Reconciler-side retype to that session with a measurement story first.

    Revisit plan (the deferred bundle)

    After the Reconciler-core PRs land (clean ownership window), revisit #139 + #140 + #167 together behind the host → MarkDirty bridge, with: (a) a theme-binding-heavy /perf leg for #167, and (b) a re-measure of #139/#140's correct (bridge-backed) gain against the ceiling above. Ship only if it clears the rps-AND-alloc bar with the bridge's correctness in place.

    — Yoga/theming follow-up workstream (companion to #682 #744, #745, #747; #683 Item B #749). The #683 Item B (FilterChildren ownership-contract) docs landed in #749.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions