5 ms·
What is the .NET IL linker and what does it do?
- taspeotis 8y agoFrom using it with Xamarin: it’s all well and good until reflection breaks it. Which is manageable in your own code but god help you if you pull in a third party assembly that uses reflection and your app suddenly breaks between debug and release configurations. The edit-test-debug cycle for linker problems can be pretty brutal too since compilation and linking takes longer in release than debug.
- kyoukushin 8y agoGood feedback! Haven't had that happen to me yet, but I guess it's just a matter of time.
- oaiey 8y agoI think it is good practice to avoid reflection as a library author. Rarely done right and even then, often source of issues (see here).
- garganzol 8y ago.NET Linker should adopt rd.xml file format. It is used to give hints about parts of the code that rely on reflection. Also consider voting for this to come true: https://github.com/mono/linker/issues/57 https://github.com/mono/linker/issues/57
- MarkSweep 8y agoI’ve been meaning to write up my expirement in maximizing the amount of things the IL linker removes: https://github.com/AustinWise/IlLinkerExample/blob/master/README.md https://github.com/AustinWise/IlLinkerExample/blob/master/RE... If you are willing to have slower application startup times in exchange for small code, you can disable the ahead of time code generation (crossgen). This gets a self-contained hello world on Windows down to ~10MB. That’s not great for a hello world, but it’s a big improvement over the ~60MB that you get without the linker.
- MaxBarraclough 8y agoSeems to me that's the sensible way to distribute an application. The user probably has a more recent compiler in their .Net runtime, and it enables machine-specific optimisation, right? I'm assuming it's the same compiler either way. It's interesting that they've blended the models traditionally used by the JVM and by Unix. Java: ship the IR, have the user's JIT generate machine-code at the last minute UNIX: ship C source, have the user compile it as part of the installation process .Net: ship the IR and either include machine-code too, or have the user compile it to machine-code, either JIT or caching 'pre-JIT' at install-time (Paint.NET does this) I suppose the 'pre-JIT' approach precludes profile-guided optimisation though, unless the IR is annotated with profiling data.
- pjmlp 8y agoJava: ship the AOT compiled binary, when the company is willing to pay for a 3rd party JDK.
- MaxBarraclough 8y agoSure, the proprietary Excelsior JET ahead-of-time-compiling JVM is out there, but their selling-points are obfuscation and startup-time, not long-running performance. OpenJDK is adding support for AOT compilation. Looks like it's still considered experimental though.
- pjmlp 8y agoThat is just one example. All major commercial JDKs, specially those on the embedded market, support AOT. And then there is that fork called Android as well.
- igouy 8y agoSubstrate VM https://benchmarksgame-team.pages.debian.net/benchmarksgame/faster/java-substratevm.html https://benchmarksgame-team.pages.debian.net/benchmarksgame/... (same gz usually means same source code) "Right now peak performance is a bit worse than HotSpot, but we don’t want to advertise that (and we want to fix it of course)." https://www.graalvm.org/docs/reference-manual/aot-compilation/ https://www.graalvm.org/docs/reference-manual/aot-compilatio...
- test1235 8y agobit off-topic, but why is it called a linker? I would have thought a more relevant name like optimiser or pruner or something.
- chrisseaton 8y agoThis is a common usage of the term. See the JVM linker for example, which performs similar tasks. A linker historically took multiple machine code files and produced an executable, possibly arranging it in a certain way following some directives, and checking connectivity. The .NET is a virtual machine, so this applies that same concept on top of that abstraction, taking intermediate representation files for that virtual machine and producing more intermediate representation, possibly re-arranged. Removing unused parts is a kind of re-arranging and checking connectivity. You could perhaps call it a 'tree-shaker' if you wanted, but the name 'linker' isn't any kind of ignorance or pretence.
- porpoisely 8y agoBecause it's part of the linking process. The linking process brings together dependencies to produce the final product ( an assembly in the .net world ). The .NET IL linker may "link" the bare minimum resources necessary, but it still links the bare minimum resources. Also optimization, pruning, etc can happen in every stage of the building process. Preprocessing, compiling, assembly, linking, etc can have optimization. In .NET optimization and pruning can occur post build. The JIT can optimize, prune, etc. Even the native code can be optimized by the runtime. Even hardware like the CPU can perform optimization on your executable. So optimizer or pruner would be an even more confusing name.
- mshockwave 8y agosimilar to LLVM linker? I mean, both of them work on abstraction representations(LLMV IR and IL) instead of working on native code directly.