Remix.run Logo
▲ theolivenbaum 4 hours ago

At the risk of being one of those people shouting "but why not language X?", I'd suggest giving modern C# a serious look. Given the background in C++ and Java, it should feel fairly familiar, while being arguably much more expressive than either and offering excellent language and runtime support for writing allocation-free code.

We've recently ported two large projects to C#, one from Java and another from C++, and seen performance improvements ranging from 30% to 300% faster, largely by focusing on eliminating allocations rather than doing anything particularly clever algorithmically.

▲Zambyte 3 hours ago | parent | next [-]

> largely by focusing on eliminating allocations rather than doing anything particularly clever algorithmically.

Did rewriting it in C# make this easier, or did rewriting make this easier?

▲theolivenbaum 2 hours ago | parent [-]

I've of course not tried rewriting it in other languages, so take that with a grain of salt. But the code is by design required to stay aligned with the source codebases as the ports are continuously updated with upstream improvements, so I don't think the gains are coming from being a very different rewrite. What I see is just how much easier it is to express efficient code in c# without loosing expressiveness, with a really nice to use low level support (Span/ReadOnlySpan, stackalloc, built in intrinsics support, easy to use pooling, etc) so you can refactor where it matters.

▲lelanthran 18 minutes ago | parent [-]

I think GP was asking if the speedup was due to eliminating allocations (maybe by doing them upfront?), not if the expressiveness of efficient code is easy.

▲giancarlostoro 4 hours ago | parent | prev | next [-]

Outside of .NET itself, C# is one of those rare things Microsoft got disgustingly correct. It's entire runtime is cross-platform and MIT licensed.

▲whs 3 hours ago | parent | next [-]

I was going to learn C# then I realize it's probably the only language that still has commercial, non domain specific paid library. (eg. Paid react component is fine for me, but a paid circuit breaker library is not)

▲pjmlp an hour ago | parent [-]

Nah, C, C++, Java, Ada, PL/I, NEWP, COBOL, Fortran, RPG,.... have enough commercial libraries to chose from.

▲skydhash 3 hours ago | parent | prev | next [-]

> It's entire runtime is cross-platform and MIT licensed

It does not run on OpenBSD. And I think it only got recently ported on FreeBSD. Yes, they are “small” platform, but lot of languages are there.

▲pjmlp an hour ago | parent [-]

Also embedded, mainframes and micros.

There is Meadows for embedded, and the oldie .NET Compact Framework, but it isn't the same regarding capabilities like real time processing.

▲pjmlp an hour ago | parent | prev [-]

Partially, if only the first AOT story wasn't like NGEN, and stuff like Span, and all the low-level improvements since C# 7 were already there in version 1.0.

Unfortunately even today their Windows team keeps being quite dismissive, pushing C++ instead.

Even the new Windows ML stuff has, yet again, better C++ and Python story than C# (WIP at the Ignite sessions time).

Unlike how Apple uses Objective-C and Swift, or Google Java and Kotlin, managed runtimes have an hard upsell on Windows division.

While Azure nowadays rather push open source projects in Go, Rust, Java than .NET.

Yeah it is a great development stack, yet its own creator has some issues pushing its adoption even internally.

▲keyle 3 hours ago | parent | prev [-]

I'd claim this is the rewrite done by people that know what they're doing that is responsible for most of the gains vs. C#'s compiler to magically make things run faster.

Sure the C# compiler is great and mature; and .NET Jit probably great too. But these massive gains can only be explained by "do less stoopid stuff".

▲theolivenbaum 2 hours ago | parent [-]

That plus having a strong language that makes it easy to express safely efficient code. Most of the performance gains come from how easy it is to measure and refactor code where it matters without impacting readability, which is something that I find a lot more difficult with other programming languages, even in this era of AI.