88 comments

[ 0.16 ms ] story [ 10.5 ms ] thread
this looks phenomenal. Can't wait to try it out.
This is s bit of an unfair comparison, isn't it?

Since WASM ships with a garbage collector that C# can use while Rust does all the memory management itself, of course it will be bigger.

EDIT: Reading OP more thoroughly I think I'm wrong. Apparently in the compared versions, the C# version ships a runtime with garbage collector.

It's a bit of an unfair comparison, the benchmarked C# code here is also post-processed which none of the other targets are. See this comment[1] on reddit where the author announced this on the /r/dotnet subreddit, Rust can go much, much lower. The title is misleading at best and a lie at worst, this is great but saying it beats Rust is a far cry from the truth except for the very narrow benchmark made to showcase this tool.

[1]: https://www.reddit.com/r/dotnet/comments/1x7wsgb/rust_just_l...

This is an entirely different toolchain from the official .NET one, which is kind of the point of the post, which is experimental, but intended to for production, not for beating benchmarks.

Rust also builds a pretty small binary, which is cool. This isn't really meant to be a 'C# is better than Rust' post, but more pointing out that Blazor (which is the official MS implementation) builds huge binaries; often >10MB, which is a real problem. This fixes that.

That's because Blazor runs on top of Mono not .NET proper if you're using WASM for Blazor, but you can also do server-rendered Blazor and all of that becomes moot.
TFA did [0] the most important stuff for minimizing Rust binaries: release mode, LTO, strip, and abort on panic. But there is a lot more you can do if you really care about Rust binary size [1]: remove location details, purge the debug formatters, rebuild the standard library for size, abort with no error message at all, and many more.

[0]: https://github.com/zion-sati/NetWasm/blob/main/docs/size-and...

[1]: https://github.com/johnthagen/min-sized-rust

I love when C gets to use non standard freestanding extensions, Rust a no std, is game on, yet when other languages do similar approaches, it doesn't count, it isn't the same language.
I think the complaint has less to do with language toolchains/extensions and more that the post processing performed on the C# output via Binaryen is not unique to the toolchain. It's analogous to comparing the toolchain outputs while zipping one output but not the other.
In both cases, you cannot simply take a random ISO C, ISO C++ or Rust crates code and hope it will work without a single code change in such environment.
IIRC no_std is a per-crate attribute and does not actually forbid use of std, so I think there's a decent chance you can use random Rust crates without changing them.

That being said, I do think it would have been nice if the author had chosen a more interesting benchmark, but alas...

I never understood the appeal of wasm outside special performance cases. We never once considered moving from Blazor server side to the wasm mode. Not one time in 5+ years did it ever come up. The whole idea turned out to be a huge distracting waste of engineering talent. Instead of chasing this idealistic wasm pipeline and struggling with weird websocket transports, we could have been writing boring old cshtml and JavaScript on top of stateless HTTP.

Unless you are building a web version of autocad or premiere, I don't see the point of engaging with this technology.

Because the abundance of javascript has made the web a bloated mess
It's for in-browser, security and portability, generally not worth it performance.

A lot of edge cases they'd rather run WASM then a JS or Python VM, it has nicer containerization characteristics. But even with those key cases - it's not necessarily a core, critical technology.

WASM is 'always on the horizon' as being important.

If we had in 2015 what we had today, there might have been a bit of a breakthrough.

> Unless you are building a web version of autocad or premiere,

Yes, but that's the use case. I don't think you'll be able to find someone respected saying "yes we should use this for all use cases regardless of what you're doing". At the other end, htmx is completely fine.

Not very hard... Rust wasm binaries are ginormous.

If you care about WASM performance, size and memory usage, Zig is a much better candidate.

Not necessarily true (especially with the new Zig Io interface), a vanilla Rust Hello World compiles to a 40 KBytes WASI blob, while a vanilla Zig Hello World compiles to 45 KBytes. Both are in the same ballpark. The vanilla C Hello World on the other hand comes out at around 4 KBytes (with the caveat that the compiler is free to replace a non-formatting printf with a direct puts call).
Been keeping an eye on the progress of NetWasm... it looks like recent versions have trimmed it further. It's down to 38 KB with WASI P2.
X is better than Y where Y is irrelevant and the difference is marginal is a low relevance observation.
Worth pointing out this is not open source, if that is an important consideration when you're comparing the two (it is to me).
Yeah, I'm not going to use a toolchain where if my project is successful, I'm going to end up having to pay.
There's something about C# that just feels so right for me for backends (as long as you stick to the more modern conventions).

Good tooling, modern language features (C# 15 has the long awaited unions, closed hierarchies), great debugging experience, etc.

If all possible metrics are considered, C# might be the best language ever created.
C# is an odd one. It's surprisingly flexible, but then oddly lacking in other areas. Quite productive, but also quite inconsistent and uncomposable.

Once you've tried a better type system (Rust), it's difficult to go back to C#. People jump through all kinds of hoops to get good performance out of it, and they're mostly able to.

Things I dearly miss from Rust when I'm using C#:

- Associated types in interfaces. (IEnumerable should not be forced to return a type-erased = heap allocated IEnumerator instance.)

- Move-only structs. (Currently, every type with value semantics is trivially copyable, even ref structs.)

"IEnumerable should not be forced to return a type-erased = heap allocated IEnumerator instance."

Foreach loops use compile-time duck typing, so if you don't intend to use your enumerable in LINQ then both the enumerable and enumerator don't need to implement any interfaces.

This optimisation covers only one common use case, but that's the way of things in C# land.

IEnumerators can also be value types So no heap allocation, just stack.

slightly off topic but a lot of things in .NET actually use compile time duct typing. like how async works To make your own task, you don't add an interface to it. You just implement a single method.

I’m aware. I would consider the fact that LINQ has caveats a failure of language design - it’s so convenient, but you just can’t use it for performance-sensitive stuff.

Meanwhile, iterators in Rust frequently outperform manual loops.

ZLinq exists: https://github.com/Cysharp/ZLinq

    > Zero allocation LINQ with LINQ to Span, LINQ to SIMD, and LINQ to Tree (FileSystem, JSON, GameObject, etc.) for all .NET platforms and Unity, Godot.
Yup, I’m a happy user of it. Writing generic code with these enumerators is extremely verbose, because the language lacks associated types.
>- Associated types in interfaces. (IEnumerable should not be forced to return a type-erased = heap allocated IEnumerator instance.)

Its not but if you call from the interface and not the implementation, it has to box because that's the contract. If you for each over a List<T> and not IEnumerable you get a stack allocated value type IEnumerator.

Devirtualization as a (JIT) compile-time optimization is possible in an increasing number of common cases, and I can think of few cases where I'd choose to explicitly consume a non-generic IEnumerable over a non-type-erased IEnumerable<T>.
Optimizations like that is not a sound basis for an architecture, though.

Like, I get that it’s “fine” for a lot of things, but it’s very not fine in situations where you really need to guarantee that a particular operation doesn’t, say, trigger GC, like in a video game.

Nice, but still lacking proper generics (i.e. à la C++ templates) and typedef.
Different use-cases.

C# is often like Java but without taking a wrong turn when it came to type-erased generics, the generics are uncomplicated enough even if slightly less powerful than what you get with the full instantiation of C++.

C++ was severely lacking before reflection came along in 26, I'm actually writing some new reflection based libraries and it's mostly a joy and quite capable.

But C++ has so many outrightly dangerous semantics when it comes to writing secure code, the coping of pointing to realtime systems,etc as another security "dimension" doesn't hold when Rust,etc exist today.

C# is good in that it's "easy" yet the performance profile of the features allows optimized code to run far closer to C++/rust/etc in performance compared to Java,etc. (that said, a wast majority is probably running like Java due to programmer patterns, but not needing to drop down to another language when it's needed feels good).

I don't know... I feel like to many C++ templates are hell and C#/Java style generics the sweet spot you want in the actual language.

If you want to do insane meta programming, you should look into Roslyn generators. It's like they added a robust code gen system to the language (even though its a compile stack feature). You basically get the full power of templates and macros but you get to use the target language (C#) instead of a bolted on macro or template language.

Generators are a bit awkward, but definitely workable and essential to the viability of native AOT.

More generally, the fact that the C# compiler is implemented as library with easy support for runtime code generation is also a powerful feature that I've found to be incredibly useful in a variety of expected and unexpected ways.

Generators in the time of AI are pretty sick, though.
sorry, but its good that C# doesnt have that crap.
That's probably the very reason it's arguably not the best language ever created. It has way too large surface area, getting close to C++ levels.

Sure, it's a valid language design, but it's also a negative in "understandability of each line of code", and thus maintainability, and even stuff like tooling, verification.

Let's make T# happen: take C#, trim away the legacy syntax from the Framework days, converge to TypeScript even more.
Not by the measure of how much accidental coupling its constructs impose upon its code: https://yannickloth.github.io/independentvariation/software/...
Maybe I'm just grumpy in the afternoon, but that page looks like it does not have a single sentence of human-written prose.
It needs better error handling.
Yes I think it's a bit underrated. The problem I find is that no one writes C# libraries that actually do anything (e.g. even basic linear algebra is pretty crap compared to python) and that the JIT is a pointless hindrance but the experience of using the stack is pretty good.
> The problem I find is that no one writes C# libraries that actually do anything

Yes, because when you think about it, why should they?

MS has showed many times how unreliable and even user-hostile they can be, so the community at large is very wary of their ecosystem in spite of real advancements.

at least supply chain issues are less problematic if everyone depends on MS :)
I agree completely regarding libraries, C# has never had the "libraries for everything", especially open source ones. The better libraries have moved to ( or always have been ) licensed too which doesn't help that impression.

I'd like to hear more about your issue with the JIT and where do you find it a hindrance?

I've had a few benchmarks lately that performed better under JIT than AOT compilation, and while that isn't always the case, the JIT, especially on dotnet 10, performs very well.

No, but when used in application areas where languages like C++ are the obvious alternatives, it has always had very good integration with native code and platform technologies, and in recent history both C# and the .NET ecosystem have been very focused on performance and platform support.

Put another way, "100% pure .NET" was never a goal in the same way it was in the Java world, but I never saw this as holding it back any more than the reliance on native code holds back languages like Python, because both have very good integration stories.

My only complaint is the lack of cross-platform support for C++/CLI, as it was a very useful tool for integrating with libraries that lack a non-C++ API.

The JIT adds basically nothing to the language other than complexity and also forces a boundary between dotnet and it's peers that I think hobbles it via harder interop.

The performance in theory can be slightly better in some niches but my point is simply that it's a huge chunk of complexity for not much gain.

Crap is probably unfair, but they are incredibly limited for numerical work compared to python or c++
Define numerical work, every user is its own snowflake.
I mean, just look at the docs for https://numerics.mathdotnet.com/ and compare them to those of https://numpy.org/doc/stable/reference/index.html#reference never mind https://docs.scipy.org/doc/scipy/tutorial/index.html#user-gu... . The amount of stuff cover by mathdotnet is tiny in comparison.
Are we comparing bullet point lists, or what actually someone needs to get their job done?
I mean, I lead an initiative to move numerically heavy microservices from c# to numerical python in my previous job (that was initially a windows shop but absorbed a linux based r&d company) because c# was so limiting. But details on that don't really fit into a HN comment.
numerics is I think OK but very expensive
C# indeed does not have a catch-all ecosystem. But for some domains (servers, UI are a mess but also pretty good, CLI is plausible), it has a very good support. Like Java but nicer (this is subjective) and faster (this is not).
Why I qualified it "for backends".

C# sweet spot is really web APIs (and all variants thereof), IMO.

> even basic linear algebra is pretty crap compared to python

I wouldn't qualify that with "even". Numerical stuff like that is one of Python's most well-developed niches, and Python's numerical ecosystem is the benchmark everything else needs to be compared against.

Its async model is a pain point, but otherwise it really does a great job of being able to accommodate a vast range of use cases
How so? Practically everything that should be async, can be, and in a straightforward fashion. Biggest pain point was the reliance on generated code that complicated debugging and potentially reduced performance, but this is being addressed in upcoming .NET releases.
It just doesnt generally work how I would expect it to work until you learn the details of how to make it work how you expect. Especially as you get into RX it gets really confusing about which execution context you should be on. And execution contexts in mobile land are pretty convoluted to setup IMO.

So yes "async" is easy, but "multithreaded/parallel" is a lot more error prone and explicit.

EDIT: I should also note I havent been in the space for a few years so Im not fully current on how it looks today

That is the saddest part: there is already a fantastic green thread concurrency for dotnet: hopac. F# then got Task {} and people kind of left hopac behind.

ConcurrentML really brought dotnet's concurrency story into the 1990s.

C# async is great. One of the best implementations of cooperative multi threading you can get, IMO.

Greenthreads or what have you are not a replacement if you want to do things like have a UI thread or bind to a native thread for interop. But you _can_ with async/await.

MS doesn't seem to care but I would say F# is an even better option than C#.

You still get interop with C# and .NET but the syntax and language is superior IMO. If only Ms would invest some resources into it.

> The 46.7 KiB program is the baseline, not the boundary.

what does this even mean

I speak claude, it means 46.7 is the minimum and it could go further.
He was absolutely right to push back though.
Slightly off topic it is just so bizarre how often Claude uses this turn of phase. It’s almost seems forced here. Anthropic has to be hard coding it to do this.
Even more off topic - Is it possible for LLM tuners/trainers to even hardcode anything?
Not literally (because they're not deterministic), but the RL process can push some behaviors so hard they become deeply ingrained and you can't remove them without more post training.

That's effectively hardcoded if the model is closed source and you're a customer. The only thing you can maybe do with it is put complex jailbreak style prompts in every conversation and that's not really practical.

Is nondetermanism a fundamental feature of LLMs? I was under the impression it was a design decision.
It's not even a just a turn of phrase, it's a way of life. - Claude, 2026
Of course, they lobbied to transfer the bloat onto the WASM runtime itself
C# will slowly fade in relevance. Nowadays it gets picked mainly when the company already has a lot of .NET in place.
Maybe I'm ignorant of some fundamental limitation here, but I cannot get excited for 47kB for a `print(42)`.
I'm trying to understand the UI story here: From what I understand, it doesn't have Blazor or anything similar.

Is this intended primarily for offloading CPU-intense calculations, or sharing code with a C# backend?

Otherwise, what's the intended story for UI? Do all that in JavaScript?

Shoutout to the [wasm-bindgen](https://github.com/wasm-bindgen/wasm-bindgen) maintainers who do an awesome job of allowing Rust to be compiled to WASM smoothly. I built an [eigenvalue solver](https://abstractnonsense.xyz/blog/2025-12-31-eigenvalue-solv...) in Rust for an interactive component for my blog, and it was super smooth going. Felt like magic! I've noticed that the binary sizes can blow up a bit by including libraries, but if you're careful I think the binaries are pretty small, tbh.