Zero C# - C# compiled to tiny native programs without a garbage collector
Show HN: Zero C#, Power of C# without any GC

Zero C# is a fork of bflat that compiles C# straight into small native executables with no .NET runtime and no garbage collector. You keep C# 15 syntax, type checking, real generics, interfaces, records, and lambdas, while memory comes from arenas you free all at once. Hello world is just 11 KB on Windows and 40 KB on Linux, and the same source runs on Linux, macOS, Windows, WebAssembly, and even DOS on a 386. A small library provides strings, collections, and I/O on these terms, with a step-by-step tutorial to get started.
The language stays, the runtime goes: the compiler still checks everything it checks in .NET, but what's missing is what a runtime would do while your program runs.
- raincole
C# already provides many tools for your performance-critical code though. You can use pointers in unsafe. You can allocate unmanaged memory with Marshal. You can avoid copy with Span. You can even manually vectorise with Vector.IsHardwareAccelerated and such.
You can also distribute apps without .NET runtime with NativeAOT.
I'm sure there are people who want a C# without GC, but for me it's just... sufficient enough.
- bob1029
The GC is a feature. Not a bug to be eliminated.
GC is not surrendering control. That seems to be HN's #1 bug bear. The sensation that someone or something is taking control away from you. The proper way to frame this is that you can actually focus on the original problem you set out to solve. Risking memory leaks is crazy when it's not something the customer is demanding. Even in gaming I think the GC is fine. There are ways to spread the impact across frames and bound the amount of time spent collecting.
If your clever scheme wouldn't work with a GC-managed heap, it probably won't work with one managed by hand either.
- YuechenLi
So... What does this have over using NativeAOT which already exists?
Keep in mind a large portion of time NativeAOT is actually SLOWER than going through RyuJIT with the only definitive benefit being smaller binaries, and it's not like you can't do Span<T> and ref structs in modern C# for manual low level memory control already.
So my question is just... why?
- buybackoff
For C# as is, what I really would appreciate is a frozen GC mode. Not zero GC, similar to Epsilon GC in Java. After initial state loading and forced GC, I would like to be able to apply a SustainedNoGC mode, that just does not even try to collect, no scanning, no pauses at all, it can only allocate. And notifications (an event) after some X bytes allocated, or just a reliable way to monitor the allocated size. The existing modes such as SustainedLowLatency or NoGCRegion are good but not enough. For some low latency workloads it's OK to allocate many GBs and then pause explicitly.
Random forced pauses are the only problem that comes from GC, otherwise it's great for throughput and just a nice feature, as a sibling comment says. No GC languages do not make code magically faster, they still have malloc/free. However, GC is surrendering control over when a program may be paused.
- hollowonepl
I’m not sure, the whole point of this language, standard libraries and runtime is built around GC. Nobody from C# world is educated or prepared to manually manage memory. This is just bare metal C++ with a lot of it stripped away and just nicer/cleaner syntax that does not inherit so much from C and POSIX archeology.
Nice POC, especially on MS-DOS but nothing truly relevant in the long run, I’m afraid