Hacker News new | ask | show | jobs
by torginus 40 days ago
That is absolutely not true. Not historically, and not now. .NET's JIT has always been very good, bar a few qualifying statements.

It used to be based on MSVC, with the most expensive optimizations trimmed, things like loop hoisting, devirtualization, generally ones with long runtimes, or ones that required whole program visibility.

But otherwise it was competent, if you wrote code aware of these limitations, it could get very close to even C++, and even on naive code, it was always very competitive (with strange wildcards, that if you used raw pointers, which are an obscure C# feature, you could get code to be even faster, due to the compiler's heritage).

It also helped, that due to MS's nature; C# was meant to be used with MS frameworks, written by people who were aware of the compiler's quirks, which you could learn if you looked at these codebases.

Sure if yo measure against LLVM-compiled static languages, it falls short in certain scenarios, but it's been soldily in the pack of other GC languages like Java or Go, and always has been.

4 comments

There's an experiment to create an LLVM-based Native AOT tool chain. I sincerely hope they work on this properly, so that we can have a properly optimized AOT. But I'm not sure if it will end up with less quirks.

https://github.com/dotnet/runtimelab/tree/feature/NativeAOT-...

Thanks for that. I had definitely noticed that the .NET JIT wasn't doing loop hoisting. And that you could get close to C/C++ performance if you did loop hoisting manually. It's useful to get some insight on .NET's actual optimization philosophy.
Only the ia64 version of the jit was based on msvc. And older versions of aot mode. Not the more typical jit targets.

I believe the new enabling technology for better codegen is tiered compilation, which has only been around for a couple years.

The old JIT was a fork of a pared-back version of MSVC; this was for all platforms, except the .NET Compact framework, which was for embedded stuff, and it was its own fork.

There were other weird things like C++/CLI which was a full-fat MSVC fork used to compile C++ either into .NET IL or x86 code which could be embedded into .NET assemblies, but could still call into .NET code.

But what most people think of as .NET (Framework) was definitely using the old MSVC-based JIT

For what it’s worth, C++/CLI is not a fork, but a feature of the VC++ compiler, which still exists and supports the latest .NET versions, with the important caveats that it’s neither cross-platform nor open source.

I, for one, would love to have a cross-platform, open source C++/CLI compiler, because there is no more convenient way to consume nontrivial C++ APIs (and buggy, poorly-specified COM APIs only documented by C++ example code) in .NET.

RyuJIT has had tiered compilation for about 10 years.
Ehhhhhhh I thought it was a bit of a mishmash, at least before ryujit?

i.e. I think the x64 framework compiler was based on MSVC, but the x86 was a bit of a different beast. That was part of why they did RyuJit in the first place, to help unify the JITs between the large divergence in how they worked [0].

One big thing being, AFAIK the old 32 bit JIT would never use SSE2 outside of some block copy type stuff. They assumed a safe baseline for most other instructions and stuck with that (although, there can be good reasons for this, e.x. consistency with x87 behavior.)

Will also add that the old x64 compiler sometimes really did do some questionable stuff, i.e. when we flipped things to use it we never really saw a perf benefit even when dealing with larger datatypes/etc that should have seen a benefit from wider registers.

RyuJit definitely has fixed that, but... again, the past is a bit hazy.

[0] - https://devblogs.microsoft.com/dotnet/ryujit-the-next-genera...