[1]: https://www.reddit.com/r/dotnet/comments/1x7wsgb/rust_just_l...
C# now beats Rust on WASM size (github.com)
sondr3 4 days ago
xxs 4 days ago
And then the person writing the code has to be an expert in all languages involved to make it even half fair, instead of just a sound-bite/click-bait.
galangalalgol 4 days ago
torginus 4 days ago
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.
giancarlostoro 4 days ago
drhagen 4 days ago
[0]: https://github.com/zion-sati/NetWasm/blob/main/docs/size-and...
pjmlp 4 days ago
aw1621107 4 days ago
I think it's also a bit unclear exactly what you mean when you list nonstandard C extensions alongside Rust's no_std and then say "similar approaches". Rust's no_std is part of the language proper so the commonality surely can't be the non-standard-ness of what is done to shrink binary sizes.
pjmlp 4 days ago
aw1621107 4 days ago
That being said, I do think it would have been nice if the author had chosen a more interesting benchmark, but alas...
CharlieDigital 4 days ago
Good tooling, modern language features (C# 15 has the long awaited unions, closed hierarchies), great debugging experience, etc.
dude250711 4 days ago
CharlieDigital 4 days ago
simonask 4 days ago
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.)
kfuse 4 days ago
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.
zarlo 4 days ago
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.
simonask 4 days ago
Meanwhile, iterators in Rust frequently outperform manual loops.
CharlieDigital 3 days ago
> 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.simonask 3 days ago
jayd16 4 days ago
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.
jasomill 4 days ago
simonask 4 days ago
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.
andygocke 4 days ago
Associated types: https://github.com/dotnet/csharplang/issues/8712
Ownership: https://github.com/agocke/csharplang/blob/ownership/proposal...
pif 4 days ago
whizzter 4 days ago
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).
jayd16 4 days ago
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.
jasomill 4 days ago
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.
CharlieDigital 4 days ago
makotech221 4 days ago
gf000 4 days ago
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.
CharlieDigital 4 days ago
humanfromearth9 4 days ago
actionfromafar 4 days ago
If you are doing greenfield, you can also make compilation much stricter with Roslyn analyzers and neutralize some of the bullet points here:
https://yannickloth.github.io/independentvariation/software/...
lelanthran 4 days ago
vips7L 4 days ago
mhh__ 4 days ago
benterix 4 days ago
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.
tester756 4 days ago
xnorswap 4 days ago
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.
jasomill 4 days ago
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.
mhh__ 4 days ago
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.
pjmlp 4 days ago
womble2 4 days ago
pjmlp 4 days ago
womble2 4 days ago
pjmlp 4 days ago
womble2 3 days ago
mhh__ 4 days ago
afdbcreid 4 days ago
CharlieDigital 4 days ago
C# sweet spot is really web APIs (and all variants thereof), IMO.
pdpi 4 days ago
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.
fortran77 4 days ago
zachsaw 3 days ago
Rust would be too expensive Engineering wise even with AI today.
JamesSwift 4 days ago
jasomill 4 days ago
JamesSwift 4 days ago
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
CharlieDigital 4 days ago
Multi-threaded/parallel is a LOT easier now with the Task Parallel Library (TPL, https://learn.microsoft.com/en-us/dotnet/standard/parallel-p...) and System.Threading.Channels. Channels in particular are nice because it can fan out and then back in to one aggregator, removing the need for self managing synchronization primitives.
I usually default to channels first, TPL when I want threads.
bjoli 4 days ago
ConcurrentML really brought dotnet's concurrency story into the 1990s.
jayd16 3 days ago
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.
SwamyM 4 days ago
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.
TazeTSchnitzel 4 days ago
what does this even mean
dionian 4 days ago
dude250711 4 days ago
NewsaHackO 4 days ago
aqfamnzc 4 days ago
tancop 4 days ago
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.
jasomill 4 days ago
ActionHank 4 days ago
Scaled 4 days ago
zarlo 4 days ago
subset 4 days ago
weinzierl 4 days ago
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.
afdbcreid 4 days ago
The comparison is unfair for other reasons (the C# runtime was optimized for WASM size and the Rust not, it's possible to be much smaller in Rust), but it's still cool.
xnorswap 4 days ago
What matters more for comparing what you get out of languages is the output of idiomatic code written against typical frameworks.
Indeed, it's still cool to see, even if it's optimised to beyond recognition, as seeing the occasional C# win is nice to keep the "re-write in rust" wolves from the door, who seem to ever lurk, especially in a world where re-writes appear easier.
afdbcreid 4 days ago
Not everything, no. You can't run C# without the .NET runtime. Some parts of it are irreplaceable.
And the Rust optimizations to shrink binary size (see https://github.com/johnthagen/min-sized-rust) are commonly done in production when it matters, not just in WASM but also in embedded.
jeswin 4 days ago
With NativeAOT, same a golang then. NativeAOT has worked wonderfully for us, and in some specific situations faster than Rust.
afdbcreid 4 days ago
I'm very curious to hear when? Because even the people that argue managed languages can be faster than unmanaged, say it because the JIT has better information at runtime. But NativeAOT cannot be better (and will be worse) than LLVM with PGO.
DannyBee 4 days ago
some of these are consistent enough that there are workloads where PGO does worse than non-PGO.
they can all be fixed, of course. which is why what you said is true in the limit, but it might not be true for right now
afdbcreid 4 days ago
jasomill 4 days ago
Microsoft already has both dynamic PGO in .NET JIT and traditional PGO in its C++ toolchain, after all.
And for that matter, there's no reason LLVM itself couldn't eventually be a target for native AOT.
afdbcreid 4 days ago
It already is implemented, I believe. The thing I wondered is how NativeAOT could be faster, which is what GP claimed.
(Also, practically it should be slower because NativeAOT is based on the JIT and the JIT is worse at optimizing than LLVM).
memsom 4 days ago
You can compile C# to an AOT exe, and when you do that it will literally only be what it needs to work, less and dynamic libs.
afdbcreid 4 days ago
fweimer 4 days ago
(Obviously those are already pretty significant gaps.)
zachsaw 4 days ago
pwpwp 4 days ago
zachsaw 4 days ago
afdbcreid 4 days ago
fweimer 4 days ago
afdbcreid 4 days ago
debugnik 4 days ago
gwbas1c 4 days ago
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?
andsoitis 5 days ago
dev_l1x_be 4 days ago
edave64 4 days ago
VimEscapeArtist 4 days ago
hvb2 4 days ago
kcb 4 days ago
bel8 4 days ago
Do you really just ask the model to pick any backend stack and pray it works?
kcb 4 days ago
FrustratedMonky 4 days ago
jedisct1 4 days ago
If you care about WASM performance, size and memory usage, Zig is a much better candidate.
flohofwoe 4 days ago
WhereIsTheTruth 4 days ago
bob1029 4 days ago
Unless you are building a web version of autocad or premiere, I don't see the point of engaging with this technology.
ChrisRR 4 days ago
bluegatty 4 days ago
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.
pjc50 4 days ago
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.