-
Notifications
You must be signed in to change notification settings - Fork 4.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
Trim unused interfaces #100000
Trim unused interfaces #100000
Conversation
So far, the compiler could only trim unused interface __methods__; the interface __types__ themselves were left alone. There is not a huge cost associated with having these extra `MethodTable`s, but it sill impacts size/working set/startup. Initial estimate showed this could actually be up to 2% for BasicMinimalApi so I decided to investigate a fix. This is an attempt to start trimming them. I chose a relatively conservative approach: * Stop unconditionally rooting the interface `MethodTable` in the implementing class `MethodTable` InterfaceList. Instead check whether someone else marked it first. * Track whether an interface type definition is used in any way. This avoids problem with variance, etc. If an interface definition is used, all instantiations that we were trying to optimize away get the `MethodTable` and won't be optimized. We should be able to do better than this, maybe, at some point. * Classes that implement generic interfaces with default methods need special treatment because we index into interface list at runtime and we might not know the correct index yet. So just forget the optimization in that case. Fixes dotnet#66716.
I vaguely remember that some part of the iOS managed static registrar or the linker pipeline may depend on the current behavior. So, cc @ivanpovazan, @simonrozsival in case they do remember the details or have some general concerns. |
@filipnavara If I understand this change correctly, I don't think this should break iOS. There are cases when we explicitly cast objects to an interface they implement and call a method on the interface. I think that falls under the second bullet point and in that case the optimization won't be applied. |
Thanks for checking! |
/azp run runtime-nativeaot-outerloop |
Azure Pipelines successfully started running 1 pipeline(s). |
ID: 100000 🎉 |
So this won't be quite the promised 2% size saving on WebapiAot template because once I started to worry about generic interfaces and the suppressions that assume IL level trimming we have within the libraries, it became 0.7%. In libraries, we have several places where we call But the good news is that Size statisticsPull request #100000
|
@dotnet/ilc-contrib this is ready for review |
/azp run runtime-nativeaot-outerloop |
Azure Pipelines successfully started running 1 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.
Nice!
Hmm, the linux-arm failure is interesting but unrelated:
Cc @filipnavara Runfo:
|
I'll wait with merging this until after #98712. I don't want to mask off how much of a regression that PR is. |
Opened #100112 |
So far, the compiler could only trim unused interface methods; the interface types themselves were left alone. There is not a huge cost associated with having these extra
MethodTable
s, but it sill impacts size/working set/startup. Initial estimate showed this could actually be up to 2% for BasicMinimalApi so I decided to investigate a fix.This is an attempt to start trimming them. I chose a relatively conservative approach:
MethodTable
in the implementing classMethodTable
InterfaceList. Instead check whether someone else marked it first.MethodTable
and won't be optimized. We should be able to do better than this, maybe, at some point.Fixes #66716.