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.
Summary
MAUI layout diagnostics appear intended to be zero-allocation when no diagnostics consumer is active. In
10.0.60,IView.Measure/IView.Arrangestill allocate whenSystem.Diagnostics.Metrics.Meter.IsSupported == true, even with noActivityListenerorMeterListener.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,000measure/arrange operations:meter-on-handler408.012~0meter-on-handler-addmetrics, no listener408.012~0Elapsed 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()EnabledA local prototype that gates on these checks restored the no-listener path to effectively
0 B/op.