[WinAppSDK] Attaching controls to the visual tree is 40x slower on MAUI than on bare WinUI
- Dominant language
- C#
- Stars
- 23.3k
- Forks
- 2k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 290
Description
### Description
Attaching a deep tree of controls to the live tree is 40x slower on MAUI than on bare WinUI 3, for similar operations.
### Steps to Reproduce
Considering this code:
```csharp
private StackLayout MakeLayout()
{
var current = new StackLayout()
{
Children = { new Label() { Text = "Inner" } }
};
for (int x = 0; x < 99; x++)
{
var panel = new StackLayout();
panel.Children.Add(current);
current = panel;
}
return current;
}
```
Attaching the resulting layout to any parent (anything in the live visual tree) is costly:

The equivalent in WinUI:
```csharp
private StackPanel MakePanel()
{
var current = new StackPanel()
{
Children = { new TextBlock() { Text = "Inner" } }
};
for (int x = 0; x < 99; x++)
{
var panel = new StackPanel();
panel.Children.Add(current);
current = panel;
}
return current;
}
```
### Version with bug
Release Candidate 2 (current)
### Last version that worked well
Unknown/Other
### Affected platforms
Windows
### Affected platform versions
net6.0-windows10.0.19041
### Did you find any workaround?
None.
### Relevant log output
_No response_
Contributor guide
Research direction
Start with the provided MakeLayout reproduction and profile the operation of attaching its 99-level StackLayout tree to a live visual-tree parent on Windows. Compare the result with the equivalent WinUI StackPanel benchmark; done means identifying and addressing the reported performance gap, with measurements showing the slowdown is substantially reduced.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- frontend, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100