Skip to content
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

Perf: Minimize QueryInterface calls, implement FastABI (Consumption) #182

Closed
Scottj1s opened this issue Apr 23, 2020 · 1 comment · Fixed by #998
Closed

Perf: Minimize QueryInterface calls, implement FastABI (Consumption) #182

Scottj1s opened this issue Apr 23, 2020 · 1 comment · Fixed by #998
Assignees
Labels
enhancement New feature or request performance Related to performance work
Milestone

Comments

@Scottj1s
Copy link
Member

Scottj1s commented Apr 23, 2020

Background

WinRT API designs are class-based, but interfaces are used to collect the API surface into versioned units. For mature APIs, such as WinUI and IXP, that means objects will implement many interfaces. Use of those interfaces creates overhead in several ways:

  1. Runtime performance overhead due to having to QI and Release for the interfaces.
  2. Increased memory consumption for caching interface pointers.
  3. Binary growth due to code generation for QI-ing for multiple interfaces.

FastABI addresses these problems by generating a "flattened" default interface, appending methods for all non-default exclusive-to interfaces (e.g., IButtonBase*) across the inheritance hierarchy for the runtime class, through a well-defined algorithm. This flattened interface is a superset of the default interface and is thus backward compatible with it for unenlightened client code. The class implementation is still responsible for responding to QI calls on non-default exclusive-to interfaces for unenlightened clients. These QIs are typically implemented as fast, lightweight COM tear-offs using the C++/WinRT fast forwarder library. Client code that is built with FastABI-enabled language projections look for a "fastabi" attribute attached to a runtime class in metadata, using it to generate the corresponding flattened vtable layout, enabling FastABI gains in client code. So, FastABI benefits only accrue when both server (class implementation) and client are FastABI-enabled.

Consumption

For C#/WinRT, the primary benefit for FastABI is on the client (consumption) side, complementing the support in native APIs like WinUI. This issue is about implementing C#/WinRT FastABI support on the client side, as described above, comprised of these steps:

  1. Generating the flattened default interface based on the FastABI algorithm.
  2. Dismantling the lazy querying and caching of non-default exclusive-to interfaces in generated class code.
  3. Adding FastABI-enabled classes to test components (TestWinRT preferably, as this is a language-general feature).
  4. Testing FastABI-enabled classes in the unit test project.

Authoring

As described, FastABI provides the biggest returns for complex class hierarchies with multiple versions of exclusive-to interfaces. A conscious tradeoff is made for implementing these interfaces as COM tear-offs instead, "lazily" allocating them on demand. Whether this applies to C#/WinRT authored classes, and whether tear-offs can be as efficiently implemented, is an open question. It seems unlikely that C#/WinRT authored types would ever approach the complexity of WinUI, for example. We may conclude that it makes little sense to implement FastABI authoring support in C#/WinRT.

@BenJKuhn BenJKuhn added this to the Release Candidate 2 milestone Jun 12, 2020
@manodasanW manodasanW added the enhancement New feature or request label Jun 15, 2020
@BenJKuhn BenJKuhn added the performance Related to performance work label Jun 16, 2020
@AdamBraden AdamBraden added this to the Release 1.1 milestone Oct 9, 2020
@AdamBraden AdamBraden modified the milestones: Release 1.2.0, Release 1.3 Jan 5, 2021
@j0shuams j0shuams self-assigned this Jan 6, 2021
@j0shuams j0shuams modified the milestones: Release 1.1.5, NET5 vNext Mar 17, 2021
@angelazhangmsft angelazhangmsft modified the milestones: NET5 vNext, Future Apr 5, 2021
@angelazhangmsft angelazhangmsft modified the milestones: Future, Release 1.3.2 Jun 22, 2021
@angelazhangmsft angelazhangmsft modified the milestones: Release 1.3.2, Future Jul 20, 2021
@angelazhangmsft angelazhangmsft modified the milestones: Future, Release 1.3.7 Sep 16, 2021
@angelazhangmsft angelazhangmsft changed the title Perf: Minimize QueryInterface calls, implement FastABI Perf: Minimize QueryInterface calls, implement FastABI (Consumption) Feb 24, 2022
@angelazhangmsft
Copy link
Contributor

We can open up another issue for FastABI (Authoring) if that becomes a need or priority.

@angelazhangmsft angelazhangmsft linked a pull request Feb 24, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request performance Related to performance work
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants