-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Don't repeat 'QueryInterface' calls for 'IReferenceTracker' when possible #113632
Don't repeat 'QueryInterface' calls for 'IReferenceTracker' when possible #113632
Conversation
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas |
Tagging subscribers to this area: @dotnet/interop-contrib |
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.
Pull Request Overview
This PR refactors COM interop code to avoid duplicate QueryInterface calls for IReferenceTracker in aggregation scenarios.
- Updated NativeObjectWrapper.Create and related methods to pass a reusable reference tracker via a new ref parameter.
- Modified DetermineIdentityAndInner to output the reference tracker pointer for later reuse.
- Introduced NullableComHolder in TrackerObjectManager.NativeAot.cs to manage the lifetime of the reference tracker pointer.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
System/Runtime/InteropServices/ComWrappers.NativeAot.cs | Updated method signatures and logic to reuse an existing IReferenceTracker pointer and eliminate redundant QI calls. |
System/Runtime/InteropServices/TrackerObjectManager.NativeAot.cs | Added NullableComHolder struct to support the new reference tracker management design. |
Comments suppressed due to low confidence (1)
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.NativeAot.cs:993
- The use of 'ref *&referenceTracker' is non-standard and likely erroneous. Please verify if 'ref referenceTracker' is intended.
retValue = RegisterObjectForComInstance(identity, inner, wrapperMaybe, flags, ref *&referenceTracker);
...nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.NativeAot.cs
Outdated
Show resolved
Hide resolved
...nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.NativeAot.cs
Outdated
Show resolved
Hide resolved
...nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.NativeAot.cs
Outdated
Show resolved
Hide resolved
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
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.
Nice
This PR optimizes the
TrackerObject
scenario inComWrappers
on NativeAOT. When we're in an aggregation scenario, we're doing a QI forIReferenceTracker
as part of resolving the object identity. Then we immediately discard this reference. However, further down we do anotherQueryInterface
for the same IID on the external object, before creating a native object wrapper.This PR avoids that, and instead passes down the pointer retrieved when determining the identity, so we can reuse it.
CsWinRT passes this flag for all objects, and in XAML scenarios pretty much all WinRT objects are tracker objects. This change will avoid that repeated QI for all of them. This is part of an ongoing effort in CsWinRT to avoid as many QIs as we possibly can.
Note
I'd recommend reviewing with whitespace off.