Performance issue - Subscribing\Unsubscribing to events
See original GitHub issueDescribe the bug When profiling our test application, we’ve seen that every event subscription takes a noticeable time. In our case, this slows down the application startup for about 200ms.
I made a small sample that shows the issue. I’ve also prepared the WPF test application so you can compare performance.
Steps to reproduce the bug
Steps to reproduce the behavior:
- Download from the attachments and open the FrameworkEventsTest solution;
- Set the following solution properties:
- Configuration - “Release”
- Platform - “x64”
- Startup Project - “FrameworkEventsTest (Package)”
- Run the application
- Click on the “Click Me” button
- Wait until the result is shown in the text editor (this may take up to 40 seconds)
- Repeat steps 4 and 5 for more accurate results
In the table below, you can see the difference between WPF and WinUI performance when subscribing\unsibscribing to the IsEnabledChanged
event.
I’ve also tried the Loaded
and the KeyDown
event and got the same results.
Case # | Description | WPF | WinUI pre-3 | |
---|---|---|---|---|
1 | Subscribe to 1 button event with 1 method 1000 times | 0 | 0 | |
2 | Subscribe and Unsubscribe to 1 button event with 1 method 1000 times | 0 | 7 | |
3 | Subscribe to 1 button event with 1000 methods 1 time | 406 | 341 | |
4 | Subscribe and Unsubscribe to 1 button event with 1000 methods 1 time | 170 | 5685 | |
5 | Subscribe to 1000 buttons event with 1 method 1 time | 0 | 217 | |
6 | Subscribe and Unsubscribe to 1000 buttons event with 1 method 1 time | 0 | 217 |
Expected behavior
I expect that cases 5 and 6 should be instant (like in WPF) since this is very close to a real scenario: in our app, we have lots of controls with subscriptions to such events as Loaded
, Unloaded
, IsEnabledChanged
, LayoutUpdated
.
I’m also surprised at the poor performance of scenario 4; however, I understand that this is synthetic and may not exist in the real application.
Version Info
NuGet package version:
[Microsoft.WinUI 3.0.0-preview2.200713.0]
[Microsoft.WinUI 3.0.0-preview3.201113.0]
Windows app type:
UWP | Win32 |
---|---|
Yes |
Windows 10 version | Saw the problem? |
---|---|
Insider Build (xxxxx) | |
May 2020 Update (19041) | Yes |
November 2019 Update (18363) | |
May 2019 Update (18362) | |
October 2018 Update (17763) | |
April 2018 Update (17134) | |
Fall Creators Update (16299) | |
Creators Update (15063) |
Device form factor | Saw the problem? |
---|---|
Desktop | Yes |
Xbox | |
Surface Hub | |
IoT |
Additional context
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
Hello @chrisglein , I’ve just measured my tests for UWP XAML and WinUI3 (Preview2) for UWP, and here are the results:
The code is the same for every project. You can find it in my attachment to the original post.
As I mentioned earlier, my main interest is in cases 5 and 6 (WinUI for Win32) since we experience the same performance issue in our application.
upd: we have our custom controls in the app; they mostly derive from
Microsoft.UI.Xaml.Controls.Control
. The ctor looks like follows:Since we reuse our code from our UWP project, I expect the performance should be the same or even better. Unfortunately, it is not.
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 5 days.