Show HN: Zero C#, Power of C# without any GC

(onurgumus.github.io)

60 points | by reverseblade2 3 hours ago

19 comments

  • raincole 2 hours ago
    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.

    • randomNumber7 30 minutes ago
      > I'm sure there are people who want a C# without GC

      There's also C++ and although it is a monstrosity the practical thing would be to use that.

      If you want a serious alternative to C++ I don't see it in C# without GC. On the other hand I have seen a lot of C++ code where normal C# would be much better suited.

    • Waraqa 1 hour ago
      NativeAOT can't compile for DOS.
      • raincole 1 hour ago
        I... guess so? But the last time I had users who use DOS was in my previous life. NativeAOT supports iOS though, which is a reasonable target for the current-life me.
    • samuelknight 1 hour ago
      NativeAOT gets rid of JIT not GC. The language is rich enough that you can avoid making garbage though.
  • bob1029 2 hours ago
    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.

    • wk_end 1 hour ago
      Garbage collection is a feature but it's also a trade-off, like most things in engineering. IMO it's a worthwhile trade-off more often than a lot of people think (though a lot of people don't think enough about it). But there's also times that it's not worthwhile, and we shouldn't pretend otherwise.
    • andai 2 hours ago
      GC is literally surrendering control.

      But it really depends on what you're doing. You can use the wrong tool for a job, but you can also use the right tool. It depends on the job.

      • jayd16 1 hour ago
        It's only surrendered control if you refuse to understand it and how to control it.
        • unrented7977 1 hour ago
          Exactly. You have a shocking amount of control over the GC if you bother to learn. Surrendering control is a choice the programmer makes by not understanding their tools.
    • dafelst 1 hour ago
      Indeed - even Unreal Engine uses GC for all its internal object management. It's not a language level thing, more a runtime entity thing, but it is there. It simplifies object lifetime management quite a bit.

      To be fair, it is also probably the number one cause of long hitches in poorly optimized UE games, and also the main contributor to class of use-after-free bugs (persisted native pointers and references to objects that weren't properly added to the object graph, though goes away with proper usage of weak object pointers and the like) so it is very much a double-edged-sword.

    • Jooror 2 hours ago
      I think some devs have painful memories of early GCs, compounded by the qualities associated with “corporate” codebases of the time. I would imagine younger programmers are writing more managed code than C and skew towards having no complaints about GCs.

      Agreed that it’s no longer a bottleneck for games; profile—and-optimize approaches are very effective and the tooling has never been better.

    • jameshart 1 hour ago
      Exactly. The problem People have with GC is not garbage collection per se, it is garbage collection pressure. The solution to which isn’t doing away with the GC, it is managing and controlling allocation.
    • 999900000999 1 hour ago
      Arguably without GC C# becomes a different language. But if you’re really comfortable with C# and can’t handle unexpected lag spikes I can see this being useful.
  • exceptione 10 minutes ago
    It builds on top of bflat, so there is a real non-vibed base there. Nice to see people take those type of bare metal efforts even further.
  • YuechenLi 1 hour ago
    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?

  • hollowonepl 2 hours ago
    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

    • andai 2 hours ago
      I was already sold, you didn't need to sell me harder!
    • jayd16 7 minutes ago
      What if I told you both Unity and Unreal use C# extensively? Plenty of game devs are familiar with memory management and C#.

      That said, I don't see how this project fits in all that nicely.

  • Dwedit 1 hour ago
    You really don't want to use C# with the "Bflat/Zero" runtime library. Even something very basic like strings is unsupported. It becomes C code with funny syntax that doesn't align well with the language.

    I have not yet tested out Beef, but it seems to be more in line with what you'd want from a native C#-like language.

  • StilesCrisis 2 hours ago
    Why did they eliminate reflection? That doesn't need huge runtime support or garbage collection.
  • Pannoniae 1 hour ago
    This thread feels like a bit of the old Dropbox thread ;)

    "what is this useful for" - You want to write native code without a runtime or GC but you also don't want to deal with C++ with its arcane rules, edge cases, an awful dependency management story and complexity in general.

    Rust is a good candidate for this as well, although it has quite a learning curve.

    "you can already do this in standard C#" - Yes but the ecosystem assumes GC so you need to write everything yourself. There are some low allocation APIs but definitely not for everything. The concept of "C# but even lower level" is something which has a place, IMO. Just like how you can technically add assembly to C#, either by linking it with nativeAOT or emitting at runtime but it's not built-in support for inline assembly, you know.

  • vips7L 2 hours ago
    Reminds me of Beef: http://www.beeflang.org/
  • amelius 2 hours ago
    The "without any GC" part has me worrying. Is this advocating to just accumulate your garbage and throw it out only once every blue moon?

    Also, does it ship with GUI libraries?

    • DougN7 2 hours ago
      “Memory comes from arenas you free all at once”
      • amelius 1 hour ago
        Yes, but this means you can only do it at very specific points in your program. E.g. after serving a request. This doesn't work for every type of program.
        • yodon 29 minutes ago
          You can do this today in vanilla C#. Pause garbage collection, then resume it. Done. Even Unity's ancient Mono variants could do this almost a decade ago.
          • amelius 3 minutes ago
            I don't see how that solves the problem.
  • OnceMoreUntoThe 1 hour ago
    Yeah, this is just a bunch of AI slop, but, ehhm... I really don't get all the CLR GC hate? Sure, if you're running a 24-months-ago Mono build, and your game performs like crap, I can sort-of sympathize, but otherwise?

    Look, I'm all-in on CLR/C#, and one of my 'apps' is a 24/7 industrial camera monitoring system, and it has been running for the past, like, 3 months, on .NET 10 with "GCSettings.LatencyMode = GCLatencyMode.SustainedLowLatency" and "stackalloc" where needed, and...

    Its performance, handling 8x ~800Mb/s streams has been... absolutely okay: 0 bytes over-allocated in the past 90 days (which is the last time my CoreOS-deployment auto-rebooted: all nodes are behind a VPN and outbound-only, so the latest OMG-CRITICAL-CVE doesn't really apply), so...

    "If it works, it works"

    • hirvi74 1 hour ago
      > * if you're running a 24-months-ago Mono build, and your game performs like crap*

      It's always the fault of the arrow and never the archer.

      • OnceMoreUntoThe 1 hour ago
        I've no idea what that's supposed to mean.
        • Dwedit 1 hour ago
          That's just another way to say "A bad workman blames his tools"
  • dosshell 2 hours ago
    I like arena allocators, but some how i fel like reference counting would have been a better match for C# philosophy, like swift.
  • jayd16 1 hour ago
    Does this need a fork? Just pause the GC and use these patterns?
  • andyfilms1 2 hours ago
    Finally, C--
    • lpedrosa 2 hours ago
      Don't you mean C♭?
  • kvuj 2 hours ago
    Doesn't C# already support AOT compilation?
  • DeathArrow 1 hour ago
    If you take GC out of C# and add arenas, why not use C or Zig already? If it's about the syntax, C's syntax is already similar.
    • tester756 6 minutes ago
      > If it's about the syntax, C's syntax is already similar.

      lol

      what about all the sane language features and stdlib?

  • pipeline_peak 1 hour ago
    I’ve always wondered what C# would be like without GC. Yet without Reflection, there really isn’t anything meaningful here. It’s just nice syntax leftover.
  • luxuryballs 1 hour ago
    vote for calling it C# Zero or hmm Z#?
  • CAP_NET_ADMIN 1 hour ago
    In the age of LLMs and agentic coding - does the syntax even matter? Do you even look at the code anymore?

    Just use Rust.