Skip to content

[Skia] ShapeVisual runs three LINQ chains per frame #24222

Closed

Description

@MartinZikmund

What would you like to be added? 💡

ShapeVisual.RequiresRepaintOnEveryFrame, DamageRegionSamplingMargin and CanPaint() are queried once per shape element per frame, and each is written as a LINQ chain (OfType + Any; OfType + Select + DefaultIfEmpty + Max; Any). Every frame therefore allocates a collection enumerator, one or two iterators and a closure per shape visual.

The sibling BorderVisual already implements the equivalent two members as plain expressions.

Why is this needed? 🤔

Walking the collection by index removes the per-frame allocations entirely.

One subtlety worth calling out for review: DamageRegionSamplingMargin needs a seen flag to preserve DefaultIfEmpty(0f) semantics exactly — 0 must be returned when there is no sprite shape at all, rather than clamping a set of margins up to 0, which a naive Max starting from 0 would do.

Measured impact 📊

Workload Metric Before After Δ
render.full-paint alloc / frame 381,830 B 271,826 B −28.8 %
render.full-paint alloc / element / frame 244.6 B 174.1 B −28.8 %
render.full-paint time / frame 70.08 ms 69.28 ms −1.1 % (noise)

Same 1,561-element rounded tree, paint only, 5 runs each, median. Allocation figures vary by <5 B across runs. Measured on a tree that already has the RectangleClip cache applied.

Renderer 🎨

  • Skia

For which platforms 📱💻🖥️

All platforms 🌍

Anything else we need to know? 💬

Found by allocation profiling — dotnet-trace attributed by type and call stack — of a headless app that project-references the real framework, then measured before/after with the same harness. Allocation figures are deterministic (byte-identical across runs); wall-clock is reported only from a quiet machine alongside untouched control workloads that would expose drift. Full methodology, raw runs and control workloads: specs/059-performance-improvements/evidence.md.

Activity

  1. added
    triage/untriaged
    on Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    triage/untriaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions