You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the core libraries, some types differentiate behaviors based on whether the instance is the base class in which the code is written or a derived type.
For example, the System.Random type's default ctor (which is the most commonly used one in production code) now checks to see whether this.GetType() == typeof(Random) or whether it's actually derived, using a different algorithm for compatibility if it's derived: https://github.com/dotnet/runtime/blob/67cca7a82062e1581edb2bced6a1428015a74eef/src/libraries/System.Private.CoreLib/src/System/Random.cs#L23-L27
But that means the linker currently sees both implementations as being used and won't trim out the one for derived types. If the linker could prove that no Random-derived types were in the whole program or were never instantiated, it could strip out the relevant branch and associated tree of code.
In the core libraries, some types differentiate behaviors based on whether the instance is the base class in which the code is written or a derived type.
For example, the
System.Random
type's default ctor (which is the most commonly used one in production code) now checks to see whetherthis.GetType() == typeof(Random)
or whether it's actually derived, using a different algorithm for compatibility if it's derived:https://github.com/dotnet/runtime/blob/67cca7a82062e1581edb2bced6a1428015a74eef/src/libraries/System.Private.CoreLib/src/System/Random.cs#L23-L27
But that means the linker currently sees both implementations as being used and won't trim out the one for derived types. If the linker could prove that no Random-derived types were in the whole program or were never instantiated, it could strip out the relevant branch and associated tree of code.
Similar patterns emerge in other types. For example, streams like MemoryStream that need to be compatible as new virtual methods are added will often do a type check to prefer the optimized implementation when it's not a derived type:
https://github.com/dotnet/runtime/blob/67cca7a82062e1581edb2bced6a1428015a74eef/src/libraries/System.Private.CoreLib/src/System/IO/MemoryStream.cs#L483-L495
The text was updated successfully, but these errors were encountered: