3 ms·
> I think we lost something with static linking when going from C to Dotnet. (And I guess Java.) Many C (and C++, especially "header only") libraries when stati
by neonsunset 1y ago
> I think we lost something with static linking when going from C to Dotnet. (And I guess Java.) Many C (and C++, especially "header only") libraries when statically linked are pretty good at filtering out unused code.
This is an interesting statement because, for example, in C version of Mimalloc you end up paying for opt-in assertions because they still exist in the code unless you compile a different version that strips them away. In C# port, you can set the same assertions/checks early with AppContext switch, and then the values will be cached in static readonly fields. Then, when JIT recompiles the code to a more optimized version, these values will become JIT constants leading to all the unreachable code to be optimized away completely (and to much better inlining of now streamlined methods).
> Even when generating a self contained EXE, the standard toolchain performs no end-linking of the program, it just bundles everything up in one file.
/p:PublishTrimmed=true
or even
/p:PublishAot=true # please note it's better to set it as a project property, but either way it requires non-optional linking
Lastly, consider that JITing the bytecode essentially acts like if everything is a single, statically-linked compilation unit since it's not subject to inconvenient compilation unit restrictions even Rust is subject to, the problems of which need to be cleaned up with link-time optimization.
- kant2002 1y agoI think you overestimate ability of Dotnet to trim unused things. As a person who spend a lot of time wandering across ecosystem and measuring what can be done, I would say we have very bulky and complicated libraries in the .Net. Just bringing HttpClient(without SSL support) add 6Mb of generated code. Minimal API gets you additional 21 Mb. And we not even talk about desktop applications here. Reflection is very very core of .Net ecosystem and you cannot reliably trim with how we use it currently
- neonsunset 1y agoLast time I checked the base web template (the one which uses minimal API) was around 10-12 MB (which is pretty good for something with a full web server, GC, async runtime and more). I’ll message you in private to see what’s going on. But otherwise yes, reflection is used heavily even when completely unnecessary.