-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Avoid POINT allocations #4754
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
Avoid POINT allocations #4754
Conversation
There are a bunch of copies around the tree of POINT interop types: some are structs (as they should be), some are classes. The latter are resulting in tons of allocations. This standardizes on using structs for all of them.
|
Can we use the same |
Do you mean use it for the interop? No, it has a different layout/size, with double rather than int fields. |
|
Such as: wpf/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/UnsafeNativeMethodsTextServices.cs Lines 750 to 766 in 192a38e
wpf/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/MS/Win32/UnsafeNativeMethods.cs Lines 159 to 169 in 192a38e
Lines 300 to 310 in 192a38e
And the POINT in |
|
Thanks. This is what I meant by "There are a bunch of copies around the tree of POINT interop types"; in fact, tons of interop is duplicated around the tree. It could certainly be cleaned up / deduped / etc., but I'm not going to do that here. |
Description
There are a bunch of copies around the tree of POINT interop types: some are structs (as they should be), some are classes. The latter are resulting in tons of allocations. This standardizes on using structs for all of them.
In a simple WPF app just moving my mouse around for a few seconds, these are the resulting top allocations:

With this PR, the highlighted line goes away.
Customer Impact
Less allocation, less GC, less pause time.
Regression
No
Testing
CI, plus validation that the allocations went away in the example scenarios I was looking at.
Risk
There is some risk here. The change itself is sound. However, the interop definitions throughout the repo are in a bit of disarray, with many different copies of the same interop types and functions, all defined subtly differently. I believe I caught all of the relevant paths interacting with these types, but it's definitely possible something could have slipped through.