Hacker News new | ask | show | jobs
by tialaramex 872 days ago
There is however no reason to imagine you can get similar optimizations yet go much faster.

Some of the optimization problems are just plain hard, indeed the optimal choices are often Undecidable for non-trivial cases, so LLVM is already trading time for better results. I have other reasons not to like LLVM, but I don't like the habit of blaming LLVM for how slow your compiler is, and Zig isn't alone in doing that.

The segue into optimisation was Andrew noting that there are too many bugs. I haven't seen Andrew speak often before, so maybe it was a joke I didn't get, but the impression I got reminded me of Herb Sutter's introduction of Cpp2 / CppFront his "New syntax" (a C++ successor language by another name). Herb gives genuine complaints people have about C++ but rather than explain why his proposal would fix them (it wouldn't) he just decides they're wrong and rewrites them, then explains how his proposal fixes these made up complaints instead. So instead of "It's much too unsafe" Herb decides the "real" problem is that it's not easy enough to write - see if it was easier you wouldn't have bugs right? An audience members even calls him out for that, but Herb is undeterred.

Like I said, maybe it's just a joke and I didn't get it. But if Andrew seriously thinks that: Zig has too many bugs => Make compiler faster makes any sense that's a problem.

1 comments

Hi, core team member here (I'm quoted in a parent comment!). The problem with LLVM is not that optimization is slow - it's perfectly acceptable for release builds to take arbitrarily long for optimal binaries. The problem is how long it takes to emit debug builds.

Take building the Zig compiler itself in Debug mode. This process takes about 30 seconds running through the Zig pipeline (semantic analysis and generating LLVM IR), and then 90 seconds just spent waiting for LLVM to emit the binary. OTOH, when using our self-hosted x86_64 backend (which is now capable of building the compiler, although is incomplete enough that it's not necessarily integrated into our development cycle quite yet), that 30 seconds is essentially the full build (there are a couple of extra seconds on the end flushing the ELF file).

I can tell you from first-hand experience that when fixing bugs, a huge amount of time is wasted just waiting for the compiler to build - lots of bugs can be solved with relative ease, but we need to test our fixes! Rebuilds are also made more common by the fact that LLVM has an unfortunate habit of butchering the debug information for some values even in debug builds, so we often have to rebuild with debug prints added to understand a problem. Making rebuilds 75% faster by just ditching LLVM would make a huge difference. Introducing incremental compilation (which we're actively working on) would make these rebuilds under a second, which would improve workflows a crazy amount. This would hugely increase our development velocity wrt both bugfixes and proposal implementation.

It's also important to note that we have quite a few compiler bugs which are [caused by upstream LLVM bugs](https://github.com/ziglang/zig/issues?q=is%3Aissue+is%3Aopen...). LLVM often ships with regressions which we report before releases come out and they simply don't fix. In the long term, eliminating the use of LLVM as our main code generation backend will mean that all bugs encountered are our own, and thus can be solved more easily.

To specifically address concerns of the optimized builds LLVM backend will still be available as an optional dependency configured via Zig's build system. Until zig's own codegen is mature enough for optimized builds, LLVM can be used to generate final optimized binary. But there is a possibility that zig's own backend can implement features (e.g. coroutines for async/await) that are not compatible with LLVM. That will force LLVM out for good.