Unofficial Hacker News companion — get notified on comment replies,
and more.
To get push notifications on iPhone or iPad, add Hack and Chat to your Home Screen: tap
Share → Add to Home Screen, then open the installed app and enable push in Settings.
Love the SL3 idea! The c3c compile times are so fast (usually <5s) that it doesn't bother me, but my other solution is to embed a tiny JS engine - also written in C3 [1].
I've been writing a 3D renderer and game engine in C3 and having a blast, hopefully it will gain popularity for games. The language is solid, fast, free of traps, and much friendlier than Rust/Zig/etc.
That's true - I'll take the compliment anyway, went through at least four revisions of the entire codebase to nail the style down and make sure it was all coherent. Thanks!
15s for a warm cache LLVM debug build for Windows sounds quite slow. My 10kLOC game takes 5s on a 8yo laptop, most of which is emitting LLVM of course.
> To give you an idea of what I am talking about, a full build of the Traction Point debug configuration, at a little over 100k LoC of Zig, takes around 24s. Changing a single line and rebuilding, with a warm cache, takes over 15s. C3 compiles the full game, without caching, in about 3s. I’ve seen it be as fast as 2.6s.
One thing I've never understood about Zig: if clang (and c3c) and Zig are both using LLVM for code generation, why is compiling so much slower in Zig for projects of similar size?
The vast majority of time is spent in LLVM, though, as reported by `--time-report`.
I did a little research and it looks like Zig puts everything into one module and feeds it to LLVM. That approach is inherently single-threaded because there's just one giant module. Clang, on the other hand, treats each translation unit as a module, so it works in parallel. Presumably c3c works the same but I'm not familiar with it.
I really wish Zig would parallelize the object file emission in a way that would benefit any selected backend (i.e. whether LLVM or their own backend).
People often generate way more IR than necessary in a naive way, and rely on LLVM to trim the fat. This simplifies the frontend, but I don't think its fair to blame LLVM for being slow in this case.
This is certainly also true. From the beginning C3 tried to keep codegen similar to Clang. After all, this is what LLVM is tested on, and it would be natural that these patterns work the best.
To get even more mileage you can do some optimizations in the frontend, before LLVM lowering (as long as it won’t break debug) to reduce IR even further.
Btw, more and more languages opt for a single compilation units, especially ones like Rust (and Zig i guess) where basically all dispatch is static and there's lots of duplicate work created by generic monomorphization (which might end up bloating binaries as well).
Considering this, I think LLVM might want to add other methods of paralallelizing computation within a single compilation unit.
There are also certain IR patterns that trigger what is essentially quadratic compilation time in LLVM.
We found that out the hard way, when we compiled our relatively simple scripting language, only to be faced with minutes of compilation for scripts of ~2000 lines. Larger tweaks to the front end to avoid certain patterns worked to a degree.
The point is, IR matters more than one might think.
what patterns do you mean? I know people don't really like phi nodes, and managing locals, so they spill everything to memory by default, which is kinda bad.
I work on the Mach[0] game engine in Zig, and I would be curious to hear if the author tried running the Zig Windows executable build under WSL2 or not, targeting Windows via cross-compilation?
In my experience Windows filesystem is very very slow, and cross-compiling from WSL (which conveniently launches native Windows exe files outside of the VM when invoked in WSL2!) has been the better developer experience for me, i.e. via `zig build run -Dtarget=x86_64-windows` to build with a Linux compiler version, cross-compile for windows, and execute on the host Windows OS.
Either way, nice article - I hope you continue writing!
The question is: if you compile your Windows executable from Linux using cross-compilation, is it faster than compiling natively under Windows? In my experience the answer is yes.
The warm-cache Zig number is what would have made me switch too. 15 seconds to rebuild after changing a line in a 100k LoC project is long enough to break the loop; a 3 second full rebuild is a different kind of tool.
It's funny that as soon as you do something well, people start assuming it's AI slop. No, the "new" site is from 2024, and it was well regarded already when it was first released. It was originally done in Astro, but has been revised since.
Also, I should add, it was made by a contributor who very generously spent a lot of time on it.
The AI policy in contributing.md on C3's GitHub[1] is fairly reasonable. "AI tools do not change contributor responsibilities", "Respect maintainer time", "Use AI as a tool, not a substitute for understanding or effort", etc.
For a while it was hard to ditch C because every alternative had worse compile speed
I eventually settled on D, stripped everything i diddn't need, discovered -betterC, and now my entire engine (~40k LOC) fully recompiles in 200ms
C3 and Odin's creators share similar concerns, and despite relying on LLVM, they achieve decent results. 3s for ~100k (assumed) codebase is quite respectble
From my experiments, Odin achieves better results, but at the cost of saturating all your CPU threads, wich is very noticeable on laptops (fans/battery) or when multitasking
I don't remember how C3 handles multithreading, and ot wich extent, but IMO, parallelism should complement compiler efficiency, not compensate for its lack of it
On the case of Zig, they promised a lot, but looks like they bit more than they can chew.. wich is unfortunate, i was (and still am) very exited for its eventual 1.0
I am not surprised you get that compilation speed out of it.
DMD (the Digital Mars D compiler) has its own backend which allows it to outclass languages based on LLVM or GCC in terms of compilation. Walter's C++ compiler was faster than the competition's as well.
Additionally, Energize C++ and Visual Age for C++ v4, allowed for a Lisp Machines/Smalltalk like development for C++, but failed in the market due to high prices and hardware requirements.
Now there is only CERN's CINT, Live++ and VC++ hot reload.
Hot reload is the raison d'etre game engines usually have scripting languages as Lua.
Hot reloading the programming language the engine is written in is definitely better though.
Incidentally, this is on the short-list of reasons why C# is very popular for writing video games. Excellent average performance, decent support for hot-reload. You just have to be careful to not produce garbage every frame, which means writing the code how you would do it in C++/Rust/Zig/C anyway.
I did a bunch of (tiny game jam) games in wasm, in C++, Rust, Zig and Odin, a while ago. I found Odin very pleasant at the time.
C3 also looks very pleasant. I haven't tried it yet. I might have to give it a go :)
Replies (1)
I've been writing a 3D renderer and game engine in C3 and having a blast, hopefully it will gain popularity for games. The language is solid, fast, free of traps, and much friendlier than Rust/Zig/etc.
[1] https://github.com/ricardobeat/boomkat
Replies (1)
Replies (1)
Replies (1)
Replies (1)
One thing I've never understood about Zig: if clang (and c3c) and Zig are both using LLVM for code generation, why is compiling so much slower in Zig for projects of similar size?
Replies (1)
Replies (2)
I did a little research and it looks like Zig puts everything into one module and feeds it to LLVM. That approach is inherently single-threaded because there's just one giant module. Clang, on the other hand, treats each translation unit as a module, so it works in parallel. Presumably c3c works the same but I'm not familiar with it.
I really wish Zig would parallelize the object file emission in a way that would benefit any selected backend (i.e. whether LLVM or their own backend).
Replies (2)
Replies (2)
To get even more mileage you can do some optimizations in the frontend, before LLVM lowering (as long as it won’t break debug) to reduce IR even further.
Replies (1)
Considering this, I think LLVM might want to add other methods of paralallelizing computation within a single compilation unit.
Continue this thread (1 replies) →
We found that out the hard way, when we compiled our relatively simple scripting language, only to be faced with minutes of compilation for scripts of ~2000 lines. Larger tweaks to the front end to avoid certain patterns worked to a degree.
The point is, IR matters more than one might think.
Replies (1)
Continue this thread (2 replies) →
In my experience Windows filesystem is very very slow, and cross-compiling from WSL (which conveniently launches native Windows exe files outside of the VM when invoked in WSL2!) has been the better developer experience for me, i.e. via `zig build run -Dtarget=x86_64-windows` to build with a Linux compiler version, cross-compile for windows, and execute on the host Windows OS.
Either way, nice article - I hope you continue writing!
[0] https://machengine.org
Replies (3)
Replies (1)
https://learn.microsoft.com/en-us/windows-server/storage/ref...
Replies (1)
Replies (1)
Replies (3)
Replies (1)
Replies (3)
Also, I should add, it was made by a contributor who very generously spent a lot of time on it.
Do you have any actual critique? Be in mind I am a real human being, with feelings you know, so it's very disheartening reading your comment.
[1]: https://github.com/c3lang/c3c/blob/master/CONTRIBUTING.md#5-...
For a while it was hard to ditch C because every alternative had worse compile speed
I eventually settled on D, stripped everything i diddn't need, discovered -betterC, and now my entire engine (~40k LOC) fully recompiles in 200ms
C3 and Odin's creators share similar concerns, and despite relying on LLVM, they achieve decent results. 3s for ~100k (assumed) codebase is quite respectble
From my experiments, Odin achieves better results, but at the cost of saturating all your CPU threads, wich is very noticeable on laptops (fans/battery) or when multitasking
I don't remember how C3 handles multithreading, and ot wich extent, but IMO, parallelism should complement compiler efficiency, not compensate for its lack of it
On the case of Zig, they promised a lot, but looks like they bit more than they can chew.. wich is unfortunate, i was (and still am) very exited for its eventual 1.0
Replies (1)
DMD (the Digital Mars D compiler) has its own backend which allows it to outclass languages based on LLVM or GCC in terms of compilation. Walter's C++ compiler was faster than the competition's as well.
Just well crafted.
Replies (1)
Now there is only CERN's CINT, Live++ and VC++ hot reload.
Replies (1)