-
Notifications
You must be signed in to change notification settings - Fork 202
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
Optimize away unused virtual implementations on abstract classes #658
Optimize away unused virtual implementations on abstract classes #658
Conversation
I would be fine with this. If we have the capability, we can also use it where possible - even it means just 0.6% for what you have measured. |
Sounds good! I'll add the comments and tests tomorrow. Also I broke multifile again so I gotta fix that (I kind of expected that). |
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.
Thank you!
This change lets us optimize away virtual method bodies on abstract classes that are overriden in all derived classes. E.g. ```csharp class Base { public virtual void DoSomething() => CallExpensiveMethod(); } class Derived : Base { public override void DoSomething() => SomeOtherMethod(); } ``` We shouldn't need to generate `Base.DoSomething` above since nobody calls that. The optimization reuses the tentative instance methods introduced last week - the first commit just extracts that into a reusable component. The second commit makes us consider references to virtual method on abstract classes tentative, until e.g. a derived class that uses the base implementation makes them not tentative anymore. We would probably get more bang if we could this to non-abstract classes too, but it's pretty difficult to discern "constructed EEType that is only constructed because it's a base of an allocated type". The biggest complication is reflection.
3326d3f
to
8c42d1e
Compare
Who disabled "rebase and merge" and for what reason? Sigh. Merge commit it is. |
I was asked to disable it to match dotnet/runtime. |
Sigh. I remember that issue in the runtime repo and it didn't make sense to me at that time and it doesn't make sense to me today after re-reading it either. Yay for consistency. |
Turns out this optimization is a bit more complicated. Adding a test case for when it didn't do the right thing, in case we want to come back to it later.
This change lets us optimize away virtual method bodies on abstract classes that are overriden in all derived classes.
E.g.
We shouldn't need to generate
Base.DoSomething
above since nobody calls that.The optimization reuses the tentative instance methods introduced last week - the first commit just extracts that into a reusable component. The second commit makes us consider references to virtual method on abstract classes tentative, until e.g. a derived class that uses the base implementation makes them not tentative anymore.
We would probably get more bang if we could this to non-abstract classes too, but it's pretty difficult to discern "constructed EEType that is only constructed because it's a base of an allocated type". The biggest complication is reflection.