[WinUI] Cache gesture event subscriptions#21959
Conversation
|
Hey there @MartyIX! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
| _areContainerTapAndRightTabEventSubscribed = false; | ||
|
|
||
| _container.Tapped -= OnTap; | ||
| _container.RightTapped -= OnTap; |
There was a problem hiding this comment.
Note that this event WAS NOT unsubscribed at all.
|
|
||
| _container.DragOver -= HandleDragOver; | ||
| _container.Drop -= HandleDrop; | ||
| _container.DragLeave -= HandleDragLeave; |
There was a problem hiding this comment.
Note that this event WAS NOT unsubscribed at all.
|
@jonathanpeppers would you mind taking a look please? |
| bool _areContainerDragEventsSubscribed; | ||
| bool _areContainerDropEventsSubscribed; | ||
| bool _areContainerPgrPointerEventsSubscribed; | ||
| bool _areContainerManipulationAndPointerEventsSubscribed; | ||
| bool _areContainerTapAndRightTabEventSubscribed; | ||
| bool _isContainerDoubleTapEventSubscribed; |
There was a problem hiding this comment.
One concern here is adding 6 bool fields is actually adding 6 bytes of memory usage for every View.
So, some ideas:
-
Could we make this one
boolfield instead? If a default view doesn't subscribe, maybe we could just store the state of all the events in onebool _subscribed;? If one event subscribes it would attempt to unsubscribe all? -
If we need all 6 distinct values, we could consider:
[Flags]
enum SubscriptionFlags : byte
{
None = 0,
ContainerDragEventsSubscribed = 1 << 0,
ContainerDropEventsSubscribed = 1 << 1,
ContainerPgrPointerEventsSubscribed = 1 << 2,
ContainerManipulationAndPointerEventsSubscribed= 1 << 3,
// etc.
}And store a single SubscriptionFlags enum in a field, that would take 1 byte instead of 6.
If there were a BenchmarkDotNet benchmark, we might know exactly how much extra memory is used. But I don't think we have a Windows equivalent of this project:
There was a problem hiding this comment.
Unsubscriptions are costly because of interops and there are always some events subscribed AFAIK so I don't think that we can go with bool _subscribed. I went with the other suggestion instead.
9f71d57 to
0e5a07c
Compare
|
Measurements with commit a5f8d56 addressing #21959 (comment) by adding |
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
jonathanpeppers
left a comment
There was a problem hiding this comment.
This looks good to me from a performance perspective. Someone familiar with these gestures on Windows should review as well. 👍
|
@rmarinho Could you take a look please? |
|
@jfversluis Could you take a look please? |
|
@Foda might be the right person here |
|
@Foda Could you take a look please? |
|
@rmarinho Is it good to be merged or does it need to wait until SR6? |
|
@rmarinho Anything else to do here? |

Description of Change
Interops operations on Windows are costly. This PR avoids unsubscribing events that were not subscribed in the first place and thus improving performance.
Speedscope
-> 70% improvement for that particular method.
I test with my complex grid sample basically.
Issues Fixed
Contributes to #21787