Zig's New Relationship with LLVM
Yes, yes, yes, yes, yes.<p>I&#x27;m going to make the kind of prediction that will set me up to be the laughingstock of HN in a few years.<p>I think in-place binary patching will be the single most consequential development in build toolchains in the last twenty years; the most consequential development since a graduate student at the University of Illinois named Chris Lattner decided to embark on LLVM. If Zig is successful in this endeavor, by the end of this decade I expect that in-place binary patching will be a feature that comes standard with most build toolchains.<p>When you reason about build systems from first principles, it becomes abundantly clear that our
current approach to linking is nuts. In both my current job and my last job, linking was by far the bottleneck in the development cycle, and a nearly unfixable one. Nothing puts a damper on getting into the zone like a sixty second link. Change a string literal somewhere? Wait sixty seconds. Fix a one-line bug in the test you just wrote? Wait sixty seconds. Change the guts of a function, but not its public interface? Wait sixty seconds.<p>Compilation is massively parallel, so if your compiler is slow, you have options. You can buy a bigger computer with more cores. You can outsource your compilation to the cloud. You can arrange your code cleverly to minimize dependencies, so changing one package doesn&#x27;t result in invalidating too many downstream packages.<p>But if <i>linking</i> is slow, you&#x27;re pretty stuck. Linking always happens, linking always happens <i>last</i>, and linking always depends on the output of all previous steps. Linking is rarely parallel and rarely incremental. You can switch from macOS to Linux, because Apple skimps on their linker. You can switch from the standard GNU linker (bfd) to the new GNU linker (gold) [0],
which has both built-in parallelism and an incremental mode. But gold is only 20-30% faster.<p>I&#x27;m not excited by a 30% speedup. Saving 30% on a 60s link still means you have a brutal 42s link; still plenty long to kick you out of the flow. A 30% speedup is the kind of speedup that&#x27;s erased in a year when your project is 30% larger. What I&#x27;m excited about is a speedup the size of several orders of magnitude! <i>That&#x27;s</i> the magic that Zig is striving for here. Change a string literal? Bam! Your binary has already been relinked, before your finger even rolled off the return key.<p>This is the kind of thing that has the potential to change our relationship with compiled languages forever. The differences between a dynamic language like Python and a compiled language like Zig become mightly slim when recompiling a large Zig program becomes as fast as restarting a Python program.<p>And the only way to get there is to redesign the compiler toolchain from start to finish. You need everything from the design of the programming language down to a custom linker to cooperate. Binary formats like ELF are not designed to be hot-swappable like this; they&#x27;re designed to be write-once. The same goes for debugging information like DWARF. They&#x27;ve developed some very clever tricks to make this work. I wouldn&#x27;t be surprised if one day there&#x27;s a custom, non-ELF binary format specifically for the use of incremental toolchains.<p>Huge props to Andy Kelley and the Zig team for having the vision and the guts to embark on this quest. (That reminds me: I am long overdue on setting up a sponsorship for the Zig Software Foundation [1] to fund this sort of work!)<p>[0]: <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Gold_(linker)" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Gold_(linker)</a><p>[1]: <a href="https:&#x2F;&#x2F;ziglang.org&#x2F;zsf&#x2F;" rel="nofollow">https:&#x2F;&#x2F;ziglang.org&#x2F;zsf&#x2F;</a>