Slow DependencyProperty performance in WinUI #1774
-
What can we expect from the performance of DependencyProperties in WinUI? We understand that the entire WinUI platform is built as a set of WinRT components, so every platform operation leads to interop. The following table lists measurements of getting/setting value of DependencyProperties in comparison to WPF (DependencyPropertyTests.zip): These are not real benchmark tests, so results are approximate
We have even tried to test DepenedencyProperties in C++, and yes, the performance of setting Border.Background is two times faster – but anyway it’s not enough. Why this is important We (at DevExpress) are working on a set of C# components for WinUI. In the latest release, we minimized amount of Dependency Property changes during virtualized scrolling in our Data Grid. This helped us make the initial loading time and scrolling performance much faster:
However, the DevExpress WinUI Data Grid still has slower scrolling speed than its WPF counterpart, even though it has significantly less features. An extreme test with 2000 text cells on screen (34 columns and 59 rows) shows that the DevExpress WPF Data Grid is three times more responsive::
These results are for text cells without any formatting (remember, the TextBlock.Text property is faster than others). For cells with different backgrounds, or for example, Check Box cells, the difference is even higher and will be noticeable in regular apps. Any improvements in DependencyProperty performance can help us (and other UI component developers) create controls that are closer to WinForms and WPF in terms of performance (or even surpass them). This will certainly increase the appeal of WinUI as the primary desktop development platform. *FPS values in above tests are the number of layout cycles per second during scrolling - measured by the following code in both platforms (WinUI and WPF): public static async Task<string> VerticalScrollingTest() {
... //initializing
double allFramesTime = 0;
int framesCount = 0;
for(int z = 0; z < 20; z++) {
for(int i = 0; i < 10; i++) {
var s = Stopwatch.StartNew();
grid.ScrollDown(80);
await CompositionTargetHelper.WaitRendering();
s.Stop();
allFramesTime += s.Elapsed.TotalSeconds;
framesCount++;
}
for(int i = 0; i < 10; i++) {
var s = Stopwatch.StartNew();
grid.ScrollUp(80);
await CompositionTargetHelper.WaitRendering();
s.Stop();
allFramesTime += s.Elapsed.TotalSeconds;
framesCount++;
}
}
return $"Fps {framesCount / allFramesTime}";
}
class CompositionTargetHelper {
static CompositionTargetHelper() {
CompositionTarget.Rendering += OnRendering;
}
public static Task WaitRendering() {
return task?.Task ?? (task = new TaskCompletionSource()).Task;
}
static TaskCompletionSource task;
static void OnRendering(object sender, object e) {
var t = task;
task = null;
t?.SetResult();
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Thank you @AlexanderEgorov for filing this detailed posting! I suggest using microsoft/microsoft-ui-xaml#1633 as the primary tracking issue for this, as this is in the WinUI/XAML ownership realm. I'd suggest adding your comment to there and keeping future discussion on that thread. Additionally, I'm starting an internal email thread to be sure key folks in the XAML and CsWinRT team have seen your detailed analysis. We're actively working on improving the performance of WinUI 3 and already have several improvements in line for 1.0 and the future, but I'll make sure dependency properties is something we're looking at too! THANK YOU! |
Beta Was this translation helpful? Give feedback.
-
Got some new numbers with 1.1-preview2, it's faster but still far away from WPF:
|
Beta Was this translation helpful? Give feedback.
Thank you @AlexanderEgorov for filing this detailed posting! I suggest using microsoft/microsoft-ui-xaml#1633 as the primary tracking issue for this, as this is in the WinUI/XAML ownership realm. I'd suggest adding your comment to there and keeping future discussion on that thread.
Additionally, I'm starting an internal email thread to be sure key folks in the XAML and CsWinRT team have seen your detailed analysis. We're actively working on improving the performance of WinUI 3 and already have several improvements in line for 1.0 and the future, but I'll make sure dependency properties is something we're looking at too! THANK YOU!