Skip to content

Only root infrastructure and dependencies for IDynamicInterfaceCastable when IDIC is implemented #116660

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

Merged
merged 20 commits into from
Jul 2, 2025

Conversation

jkoritzinsky
Copy link
Member

Implement a mechanism to conditionally root [RuntimeExport] methods based on the type corresponding to their feature being used. Use this mechanism to only root IDynamicInterfaceCastable logic when someone implements IDynamicInterfaceCastable and provide "default" implementations that should never be called in the bootstrapper when IDIC is unused.

Additionally, enhance the ScannedDevirtualizationManager to make two observations that we can optimize around:

  • Note when IDynamicInterfaceCastable has any implementors
  • If a [DynamicInterfaceCastableImplementation] type is rooted but IDynamicInterfaceCastable is not, the interfaces implemented by the attributed type still can have a known set of implementors.

Finally, adjust the "what type handle to use for casting" logic to only root a MaximallyConstructableType symbol when the target type is not IDynamicInterfaceCastable and when IDynamicInterfaceCastable is implemented in the compilation (based on DevirtualizationManager).

@jkoritzinsky
Copy link
Member Author

I've adjusted the InterfaceDispatchCellNode to do the same optimization as the cast target symbol optimization and that has allowed much of this work to cleanly work.

With the current changes, we have 1.7kB from IDynamicCastableSupport (and 32 B from IDynamicInterfaceCastable) preserved even when IDynamicInterfaceCastable is not used. I'll see if I can adjust the body substitutions logic to allow us to stub that out when IDynamicInterfaceCastable is unused.

@jkoritzinsky
Copy link
Member Author

I've added a commit to explicitly substitute away the entry-point to the logic that I couldn't get trimmed away so we can get most of the size savings now.

@jkoritzinsky jkoritzinsky marked this pull request as ready for review June 20, 2025 19:35
@MichalStrehovsky
Copy link
Member

(Sorry for the slow reaction time, missed this PR went out of Draft)

@jkoritzinsky jkoritzinsky enabled auto-merge (squash) July 1, 2025 22:55
@jkoritzinsky jkoritzinsky merged commit 74076ee into dotnet:main Jul 2, 2025
147 of 159 checks passed
@jkoritzinsky jkoritzinsky deleted the idic-conditional-rooting branch July 2, 2025 04:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants