3 ms·
Yes dead code elimination is also called tree shaking and it is typically done at compile time. However for .NET, since you can use reflection to load any type
by algorithmsRcool 9y ago
Yes dead code elimination is also called tree shaking and it is typically done at compile time. However for .NET, since you can use reflection to load any type in an assembly and call any method dynamically, removing a method is isn't statically called could cause you to fail at runtime.
Since reflection and dynamic invocation is a major feature of the runtime, they have avoided this optimization before.
- SideburnsOfDoom 9y ago> However for .NET, since you can use reflection to load any type in an assembly and call any method dynamically, removing a method is isn't statically called could cause you to fail at runtime. Indeed. it's not that common, but I would expect it to happen. One example is that many IoC Containers allow you to scan assemblies and register all class + interface pairs that match given rules. There has to be some safety-hatch to express "yes, I really want to keep that class and its methods. Don't strip them out". This seems to be documented here: https://github.com/dotnet/core/blob/master/samples/linker-instructions-advanced.md#limitations https://github.com/dotnet/core/blob/master/samples/linker-in...