Skip to content

MAUI 10 layout diagnostics no-consumer path is not zero-allocation #35473

Description

@AdamEssenmacher

Summary
MAUI layout diagnostics appear intended to be zero-allocation when no diagnostics consumer is active. In 10.0.60, IView.Measure / IView.Arrange still allocate when System.Diagnostics.Metrics.Meter.IsSupported == true, even with no ActivityListener or MeterListener.

This can cause unnecessary allocation and GC churn during normal layout, especially in configurations where meter support is enabled, such as debug or non-optimized builds.

Observed Impact
Local probe over 10,000,000 measure/arrange operations:

Mode 10.0.60 B/op Patched B/op
meter-on-handler 408.012 ~0
meter-on-handler-addmetrics, no listener 408.012 ~0

Elapsed time in affected no-listener paths also improved by roughly 77-83% after gating diagnostics, though allocation/GC churn is the main issue.

Expected
With no active MAUI diagnostics consumer, layout diagnostics should avoid tag construction, instrumentation boxing, and per-operation allocation.

Likely Cause / Fix
Layout instrumentation is entered based on RuntimeFeature.IsMeterSupported, rather than checking for actual consumers:

  • ActivitySource.HasListeners()
  • layout counter/histogram Enabled

A local prototype that gates on these checks restored the no-listener path to effectively 0 B/op.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-layoutStackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions