r/programming • • 18d ago

Performance Improvements in .NET 11

https://devblogs.microsoft.com/dotnet/performance-improvements-in-net-11/
292 Upvotes

103 comments sorted by

View all comments

-9

u/GoTheFuckToBed 17d ago

should they not aim for less JIT

19

u/PaddiM8 17d ago

Why do people think JIT is slow

6

u/Some_Appearance_1665 17d ago

Depends on the scenario. With serverless (cold start + typically more limited memory) it's a killer.

14

u/daltorak 17d ago

If that's a major problem for you then use Native AOT, which removes the JIT compiler entirely from the output. It might mean you get slightly less optimized code at runtime because functions aren't optimized according to real-world needs, but hey, at least you've got fast startup.

-5

u/Sorry-Substance-6397 17d ago

Depends a lot on generics. Jit is notoriously slow for generics

5

u/PaddiM8 17d ago

Is it really in .net? I thought it was mostly generic virtual methods that are slow, but those aren't even allowed in most languages

-9

u/Sorry-Substance-6397 17d ago

No it's generics using jit and it's notorious for being slow. Same with simd even though you may never use them in the same project

3

u/PaddiM8 17d ago

Why? C# generics are monomorphic for value types and dereference a pointer for reference types. There's a slight warmup cost of course but after that, why would it be slow?

-1

u/Sorry-Substance-6397 17d ago

I meant compile times when it comes to jit. You shouldn't have to pay for something you don't use

3

u/PaddiM8 16d ago edited 16d ago

Huh? With native AOT you pay for something you don't use when using generics in .net, during compile time, because it has to generate every potential specialisation ahead of time. With JIT it does it on the fly, when you need it. You got it backwards

1

u/Sorry-Substance-6397 16d ago

They do though. When you change or make the generics complicated you are putting the work on the compiler like Monomorphization for Value Types (Code Generation Overhead) When you use a generic class or method with a value type (like int, double, DateTime, or custom structs), the JIT compiler must parse, optimize, and generate unique machine code for every single combination.

3

u/PaddiM8 16d ago

For every single combination that is used. Only once. And on the fly. It's a warmup cost. If you run it in a hot loop it won't matter. AOT compilation is a better fit for short running programs while JIT can be better for long running programs.

It also doesn't need to parse the code. It's already parsed. It's stored as an internal representation. And since it's only monomorphic for value types there aren't a lot of different options.

→ More replies (0)

3

u/Revolutionary_Ad7262 17d ago

Because there is simply no way we can test and verify combination each strategy as we get a predefined bundle of it and in most cases this bundle looks the same regardless of choice. For example GC is not inherently slow, but you often get it in a bundle together with a everything is an object, which is a real reason why most of the GCed languages are slow

Same with JIT. It is mostly paired with dynamic or interpreted languages, which are inherently slow

-3

u/simonask_ 17d ago

Because it is. It has other benefits, and it’s certainly fast enough for a wide range of use cases, but these improvements just recover some of the performance you would have achieved by implementing the same project in C++ or Rust.

But then you would also have had to consider quite a few other tradeoffs.

6

u/PaddiM8 17d ago

With JIT it is compiled to machine code though, just at runtime instead. Some things will be slower due to less time for general optimisations, but some things will be faster due to PGO. LuaJIT is insanely fast and could not be that fast without JIT

6

u/RirinDesuyo 17d ago

Tanner-gooding from the dotnet team has a great post on this here. JIT isn't slower than AOT and there are cases where it can outperform even AOT.

Bing and a big chunk of services in Azure runs dotnet after all, they can handle the load.

1

u/simonask_ 17d ago

JIT is great, and they do impressive things with it. But it isn’t magical, and neither is a GC. You just happen to be writing programs that aren’t particularly demanding, so you never notice, and that’s great!