Consider analyzing call sites to methods to determine if portions of the callee can be trimmed · Issue #1868 · dotnet/linker (original) (raw)
I've seen this in a few cases in corelib. For example, methods that take a StringComparison and then have six cases in a switch, one for each of Ordinal, OrdinalIgnoreCase, InvariantCulture, InvariantCultureIgnoreCase, CurrentCulture, and CurrentCultureIgnoreCase. Each of those ends up having a different supporting implementation. But in a default Blazor wasm app, a given method generally only ended up having a couple of callers, often always with the same harcoded value, e.g. LastIndexOf(..., StringComparison.OrdinalIgnoreCase)
. The linker could in theory examine all call sites, and if all were const values (or could otherwise be determined via flow analysis), determine which code paths in the callee were and were not hittable, and then trim implementation accordingly. It's also likely a very expensive thing to do.