Skip to content

Grid.ValidateDefinitions boxes a collection enumerator twice per measure #24224

Closed

Description

@MartinZikmund

What would you like to be added? 💡

Grid.ValidateDefinitions iterates definitions.GetItems(), whose implementations return the backing DependencyObjectCollection<T> as IEnumerable<DefinitionBase>. DependencyObjectCollection<T>.GetEnumerator() returns IEnumerator<T>, so the List<T>.Enumerator struct is boxed — and ValidateDefinitions runs twice per Grid measure, once for rows and once for columns.

Why is this needed? 🤔

DefinitionCollectionBase already exposes both Count and GetItem(int), so no new API is needed, and GetItem is _inner[index] — the same sequence the enumerator walks. GetItems() then has no callers left and can be removed from the interface and its two implementations rather than left dead.

Measured impact 📊

Workload Metric Before After Δ
grid.full-pass alloc / pass 79,113 B 51,833 B −34.5 %
grid.full-pass alloc / element 58.0 B 38.0 B −34.5 %
grid.full-pass time / pass 3.11 ms 3.08 ms ±0 (noise)

Workload run alone in both configurations, change reverted and re-applied on the current tree, 5 runs each, median. Allocation figures byte-identical across runs.

27,280 B saved over 341 grids = 80 B per grid per pass — two boxed List<T>.Enumerators at 40 B each, one for rows and one for columns, matching the constant measured independently in VisualTreeHelper.

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