-
Notifications
You must be signed in to change notification settings - Fork 128
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
Mark types needed for instance checks only if they are ever instantiated #1595
Conversation
This seems rather niche. Is there some specific scenario it helps with? Does it help reduce size in general? Just asking out of curiosity so that I understand it's impact. |
It works in general, few large size samples I tried saved about 3% |
Oh, that's a pretty cool win. If one has if (foo is Bar)
{
((Bar)foo).SomeMethodOnBar();
}
if (foo is Bar b)
{
b.SomeMethodOnBar();
} And |
That's the next level (on my list too for later) but this is useful even without it as the type itself can bring large dependencies. Few examples where this kicks in |
It's not clear to me if this could alter static constructor execution, but it sounds like there is concern that it could? If the potential exists for this to impact static constructor execution my preference would be to put this behavior behind a new |
I think you are catching some niche scenario that let's you knock out a large section of unused code. Our code size tests are showing only slightly above 0% reduction.
That's not to say this isn't worth doing. It certainly is if it helps some case by 3%. 3% is hard to come by. But based on this I would say that I would definitely like to see a |
That concern was addressed. |
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.
Sorry for being late to the party... just a couple of minor comments.
@@ -53,6 +53,8 @@ public partial class MarkStep : IStep | |||
protected List<TypeDefinition> _typesWithInterfaces; | |||
protected List<MethodBody> _unreachableBodies; | |||
|
|||
readonly List<(TypeDefinition Type, MethodBody Body, Instruction Instr)> pending_isinst_instr; |
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.
Nit: member fields start with _
in this class - so to keep to consistent it should be _pending_isinst_instr
.
{ | ||
Console.WriteLine (o is I2); | ||
} | ||
|
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.
I would also add a test where the class T6
is used in is
but also where a static member on T6
is called. So the class is not instantiated, but it will be kept. I think we will still rewrite the is
in that case.
TestTypeCheckKept_1 (); | ||
TestTypeCheckKept_2<string> (null); | ||
TestTypeCheckKept_3 (); | ||
TestTypeCheckKept_4 (null); |
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.
I would also add one test which uses as
- I know it translates to the same instruction, but it would be good to have it for completeness.
…ted (dotnet/linker#1595) Commit migrated from dotnet/linker@3a38290
Commit migrated from dotnet/linker@bae5bd8
No description provided.