DataGrid with Fluent theme and lots of columns is 10x slower removing from view
See original GitHub issueDescribe the bug
When the Fluent theme is used, a DataGrid with lots of columns (20+) is very slow when removed from the UI. (about 20x slower than adding) Using the base Light theme is about 70x faster when removing the control.
To Reproduce
- Clone https://github.com/garyhertel/AvaloniaDataGridPerfTest.git
- Start App
- Click “Toggle” button to toggle DataGrid on and off
- Look at the Debug output for times
- You can switch the theme in the App.xaml
A few notes:
- Hardcoding or resizing the MainWindow Width cuts the performance hit by 10x, but this is still significantly slower than the base theme. My app also relies on the DataGrid autosizing itself so I’m not sure this can be permanently hard coded.
- I’m using a widescreen monitor so the default window width is ~2800 pixels
Expected behavior
Using the Fluent theme and lots of DataGrid columns, the DataGrid removal should match the performance of the base light theme.
Alternatively, some workaround to speed up removal would help. (although other people will probably run into this problem too)
Screenshots

Desktop (please complete the following information):
- OS: Windows 10 Pro
- Version: Avalonia 0.10.15
Additional context
Timings for the sample app using using different themes:
Width=2864
Light Theme, resized and half of columns showing
DataGrid added, [time = 52ms ]
DataGrid removed, [time = 56ms ]
DataGrid added, [time = 0ms ]
DataGrid removed, [time = 40ms ]
DataGrid added, [time = 0ms ]
DataGrid removed, [time = 71ms ]
Light Theme, all columns showing
DataGrid added, [time = 57ms ]
DataGrid removed, [time = 152ms ]
DataGrid added, [time = 0ms ]
DataGrid removed, [time = 137ms ]
DataGrid added, [time = 0ms ]
DataGrid removed, [time = 134ms ]
Fluent Light, resized and half of columns showing
DataGrid added, [time = 58ms ]
DataGrid removed, [time = 669ms ]
DataGrid added, [time = 0ms ]
DataGrid removed, [time = 662ms ]
DataGrid added, [time = 0ms ]
DataGrid removed, [time = 661ms ]
Fluent Light, all columns showing
DataGrid added, [time = 57ms ]
DataGrid removed, [time = 9876ms ]
DataGrid added, [time = 0ms ]
DataGrid removed, [time = 9788ms ]
DataGrid added, [time = 0ms ]
DataGrid removed, [time = 9789ms ]
Issue Analytics
- State:
- Created a year ago
- Comments:9 (9 by maintainers)

Top Related StackOverflow Question
Seems that the reason the above method is showing up so prominently in profiling is that the
Window.DottedLineFocusAdorner :is(Control)style is adding thousands of handlers toClasses.CollectionChanged:There are nearly 8000 class listeners being added to the window’s
Classescollection:Thanks for all the quick fixes everyone! This was the biggest blocker for the Fluent upgrade, so hopefully I can get that updated soon!