runtime icon indicating copy to clipboard operation
runtime copied to clipboard

Make it possible to eliminate branches guarded by IsEnum

Open MichalStrehovsky opened this issue 3 months ago • 3 comments

We use this check in CoreLib and currently it includes some unreachable code with a big closure.

MichalStrehovsky avatar Mar 28 '24 11:03 MichalStrehovsky

Does handling the internal IsActualEnum here too make sense?

MichalPetryka avatar Mar 28 '24 22:03 MichalPetryka

Does handling the internal IsActualEnum here too make sense?

This only helps things like typeof(T).IsEnum. It doesn't do anything for when we have a System.Type from who-knows-where. If we use IsActualEnum on typeof(T) anywhere, we should just switch it to IsEnum.

MichalStrehovsky avatar Mar 28 '24 22:03 MichalStrehovsky

Wondering if this could also give us some size savings in CsWinRT. Eg. we have a few branches on this there (example):

image

Sergio0694 avatar May 13 '24 10:05 Sergio0694

Wondering if this could also give us some size savings in CsWinRT. Eg. we have a few branches on this there (example):

Yes, that would probably help here.

I'll merge this then. I wasn't fully convinced we really want this without the rest. Despite the impression I'm giving here, I don't particularly like we do this IL rewriting.

Size statistics

Pull request dotnet/runtime#100399

Project Size before Size after Difference
avalonia.app-linux 24496560 24492464 -4096
avalonia.app-windows 22036480 22031360 -5120
hello-linux 1377040 1348240 -28800
hello-minimal-linux 1110696 1085992 -24704
hello-minimal-windows 885248 864256 -20992
hello-windows 1133056 1109504 -23552
kestrel-minimal-linux 5772000 5767904 -4096
kestrel-minimal-windows 5072384 5070848 -1536
reflection-linux 2294656 2294656 0
reflection-windows 1944576 1944064 -512
webapiaot-linux 10249144 10228632 -20512
webapiaot-windows 9206272 9188352 -17920

MichalStrehovsky avatar May 13 '24 11:05 MichalStrehovsky