-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WinUI] Cache gesture event subscriptions #21959
[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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
bool
field 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.Windows.cs
Outdated
Show resolved
Hide resolved
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@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