Repository navigation
Description
Summary
When a .NET MAUI control is first displayed, its handler calls PropertyMapper.UpdateProperties() to push every mapped property from the virtual view to the platform view. For a typical control like Label, this means ~49 mapper calls — even though the developer may have only set 1 or 2 properties (e.g., Text). The remaining ~47 calls push values the platform view already has by default.
In an app with many controls, this "death by a thousand cuts" becomes a measurable startup cost. Each mapper call involves reading the C# property value, type conversion, and a platform interop call (JNI on Android, Obj-C message send on iOS/macCatalyst, WinRT on Windows).
Background and prior work
This issue is a continuation of the work in:
- [performance] all
PropertyMapper's set the same values over and over #17303 — Original issue by @jonathanpeppers identifying that PropertyMappers set the same values repeatedly - Improve PropertyMapper performance #28077 — @albyrock87's
PropertyMapperperformance improvements (cached mappers, execution ordering) - Skip useless handler mappings calls while connecting #27259 — @albyrock87's per-mapper
IsConnectingHandler()guards (merged into .NET 9 SR9, showing 43% iOS / 12% Android / 22% Windows improvement forSetVirtualView) - Skip initial assignments in property mapper (take 4) #27042 — @MartyIX's centralized approach to skip mappers at the
PropertyMapperlevel
When #17303 was closed, @PureWeen noted: "The next effort here will be to assess where we could still make some additional changes to glob together mapper changes."
This issue proposes a complementary, centralized approach that goes further than the per-mapper guards in #27259 by skipping at the PropertyMapper.UpdateProperties() level itself — before the mapper delegate is even invoked.
The problem in detail
During ElementHandler.SetVirtualView(), the handler enters Connecting state and calls PropertyMapper.UpdateProperties(). This method iterates all mapper keys and calls each mapper delegate unconditionally.
Benchmark setup: A test app with 500 controls (50 each of Label, Button, Entry, Switch, Slider, CheckBox, ProgressBar, ActivityIndicator, Editor, SearchBar). Most properties are left at defaults — only Text, Placeholder, Progress, and IsRunning are explicitly set. We measured the time from app startup to the Loaded event on the main page, which captures the full handler connection and layout pipeline.
With per-key instrumentation, we observed 24,727 total mapper calls during handler connection for 500 controls (~49 per control). Of these:
- 13,567 (55%) were for properties the developer never set (e.g.,
CharacterSpacing,TextColor,Rotation,Shadow) - ~5,500 were for ViewHandler base properties that already short-circuit via
IsConnectingHandler()(e.g.,TranslationX,Scale,AnchorX) — they enter the C# method, check a flag, and return, but still pay method dispatch cost - ~5,600 were for properties whose mapper ran, read the default value from
BindableObject, and pushed it to the platform — where the platform view already had that same default
Proposed optimization
Skip mapper calls for properties that haven't been explicitly set, checked at the PropertyMapper.UpdateProperties() level:
- If the handler is in
Connectingstate (first-time setup) - And the virtual view implements
IPropertyDefaultChecker - Then for each mapper key, call
IsPropertySet(propertyName)to check if the property was set by the developer - Skip the mapper call if the property is still at its
BindableProperty.DefaultValue
This is a centralized, cross-platform approach — it works for all controls and all platforms automatically, without modifying individual mapper methods.
Prototype implementation (3 files, ~80 lines)
- New internal
IPropertyDefaultCheckerinterface withbool IsPropertySet(string propertyName) BindableObjectimplements it usingIsSet()+ a per-Type static cache to resolve property names →BindablePropertyinstancesPropertyMapper.UpdateProperties()checks and skips duringConnectingstate
Branch with prototype: dev/simonr/skip-default-mappers
Benchmark results
Android (Samsung Galaxy, arm64, Release, 5 runs each)
| Configuration | Median startup-to-Loaded | Mapper calls |
|---|---|---|
| Baseline | 1,718 ms | 24,727 |
| Optimized | 1,403 ms | 11,160 |
| Improvement | 315 ms (18.3%) | 13,567 skipped (55%) |
Standard deviation across runs: ~27 ms — very consistent.
Mac Catalyst (macOS, arm64, Debug, 5 runs each)
| Configuration | Median startup-to-Loaded | Mapper calls |
|---|---|---|
| Baseline | 6,550 ms | 24,342 |
| Optimized | 5,992 ms | 10,740 |
| Improvement | 558 ms (8.5%) | 13,602 skipped (56%) |
The higher percentage improvement on Android (18.3% vs 8.5%) confirms that JNI interop overhead makes each skipped mapper call more impactful.
Note on the measurement: These are total app startup times (static initializer →
Loadedevent), not isolatedSetVirtualViewmeasurements. The mapper work is a fraction of the total, so the actual time spent in redundant mapper calls is a subset of the 315 ms / 558 ms improvements. The rest of the improvement comes from reduced GC pressure and avoided downstream work triggered by property setters.
Remaining opportunity
Instrumentation shows that even with this optimization, ~9,000 mapper calls still execute unnecessarily for 500 controls, because:
-
Unresolved property names (~5,000 calls): Properties like
Semantics,Border,Toolbar,IsInAccessibleTreedon't have a matchingBindablePropertyfield on the control type (they're computed properties, attached properties, or interface-only). The conservative fallback returnsIsPropertySet = trueto avoid breaking anything. -
Properties reported as "set" by styles (~4,000 calls): Properties like
Visibility,IsEnabled,MinimumHeight,MaximumWidthhave theirBindableProperty.IsSet()returntruebecause MAUI's implicit style system touches them — even though the developer never set them and the values match platform defaults.
Addressing these two categories could skip an additional ~9,000 calls per 500 controls, potentially doubling the improvement.
Next steps
This issue is filed to track the opportunity and share the data. The prototype is not immediately mergeable — it needs:
- More thorough testing — especially around controls with non-standard defaults and custom handlers
- Correctness validation — the assumption that freshly-created platform views have matching defaults must be verified across all controls and platforms
- Better property resolution — replace the reflection-based
BindablePropertylookup with something that handles attached properties and computed properties - Consideration of source generators — to eliminate the reflection cost entirely
Activity
albyrock87 commentedon Feb 17, 2026
@simonrozsival the approach seems good but I'm seeing a few critical points:
Visibilityneeds to be mapped even on the default value because they may have to set some additional flag on the native viewsimonrozsival commentedon Feb 17, 2026
I agree. I will need to spend more time investigating this. One direction we could explore is to allow skipping for some known "safe" properties. Custom mappers should not be affected.
simonrozsival commentedon Feb 17, 2026
@albyrock87 Thanks for the feedback — both points are valid and important.
On custom mappers (AppendToMapping/ModifyMapping):
You're right that this prototype would silently skip user-customized mappers. If a developer does:
...and the
Labelhas default opacity, our optimization skips the entire "Opacity" mapper — including their appended code. There's no way to distinguish "original framework mapper" from "framework + user-appended" at the key level today.A possible solution: track which keys have been modified via
AppendToMapping/PrependToMapping/ModifyMappingand never skip those. This could be aHashSet<string>on thePropertyMapperpopulated byModifyMapping(). That way, the optimization only affects framework-defined mappers with no user customization.On Visibility and other "needs mapping at default" properties:
Good point.
MapVisibilityon Android does more than just setView.Visibility— it may also set additional flags depending on the control type (e.g.,ActivityIndicator).In the prototype, I started with a basic
IsPropertySet()check that resolved mapper key names toBindablePropertyinstances via reflection. That version skipped ~55% of mapper calls. However, it missed many properties because the mapper key name often differs from theBindableProperty.PropertyName(e.g., mapper key"Visibility"vs property"IsVisible", or"MinimumHeight"vs"MinimumHeightRequest"), and attached properties (likeSemanticProperties.Description) aren't on the control's type hierarchy. I then expanded the resolution with name aliases and attached-property scanning, which brought the skip rate to ~85% — but as you point out, some of those properties (likeVisibility) genuinely need their mapper to run even at the default value.The safest approach may be the one you chose in #27259 — let individual mapper methods decide whether to skip, rather than making a blanket decision at the
PropertyMapperlevel. The data from this experiment (which mappers are no-ops at defaults, how many calls there are, etc.) could help identify which additional mappers could benefit fromIsConnectingHandler()guards beyond the ones you already added.I'll keep this issue open to track the investigation and data. The prototype is not meant to be merged as-is — it's an experiment to quantify the opportunity and find the right approach.
albyrock87 commentedon Feb 18, 2026
@simonrozsival yes I believe my approach is the only one that fits all the needs.
I also remembered another scenario.
It seems it's not legitimate, but the code kind-of allows it, which is the possibility to switch virtual view on the same platform view.
This is a scenario where setting the default value is actually needed to reset an eventual custom value.
See https://github.com/dotnet/maui/blob/43db9d77f2ff59999dea36ab8befb8541e919013/src/Core/src/Core/Extensions/InternalElementExtensions.cs
I think that those extension methods should be made public, and the property checker should be available at mapper level.
This way even appended or overridden mappers could check the handler connection state and whether the property was set.