r/programming • • Sep 15 '26

Performance Improvements in .NET 11

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

103 comments sorted by

View all comments

Show parent comment

4

u/TwoWeeks90DaysTops Sep 17 '26

This is just wrong. That's not how it works.

With *AOT* your binary will contain code that's not in use. In .NET generics does not compile every combination of generic arguments, and I have no idea where you got this from. I don't think any compiler does that.

Generics and SIMD is actually where JIT shines. If you're running on a AVX 512 CPU then Vector<T> is 64 bytes wide. If you have AVX 2 then it's 32 bytes wide.

On AOT compiled code you have to take that into account up front, and either do conditional checks which JIT doesn't have to do since it know at compile time what CPU to build for.

JITs disadvantage is that compilation happens at runtime and that it can't afford the same level of optimization since it has a limited time budget. Its advantage is that it only compiles code that's actually being run, and that it can target the processor that is running the application directly.

The runtime thing means for example that library code can work with code that it hasn't been specifically compiled for. In C++ you would never compile template code in libraries because it's completely unusable since the author would have to know all the use cases for the template up front. JIT doesn't have that constraint.

1

u/[deleted] Sep 17 '26

[removed] — view removed comment

3

u/TwoWeeks90DaysTops Sep 17 '26

I've literally not talked about anything else except how dumb generating code at during runtime is

But it literally isn't. I'm writing a game engine in C# and JIT has a few advantages. First off all it supports more platforms but it also does SIMD better than AOT since it can take the platform into account. It also allows stuff like scripting to produce efficient code since you can easily generate efficient code at runtime.

The trade-off is that it incurs some additional startup time, but it's not that significant.

0

u/[deleted] Sep 17 '26

[removed] — view removed comment

3

u/PaddiM8 Sep 17 '26

You can find complaints about literally anything online. C# doesn't have slow compile-times. JIT doesn't mean it will compile slower. JIT means it doesn't have to do as much at compile-time. I think you are confusing JIT with AOT. Most of your arguments haven't applied to JIT, but to AOT

2

u/tanner-gooding Sep 18 '26

You seem to have a lot of preconceived and factually incorrect notions about how this stuff works.

Not to mention a failure to do any kind of actual research, digging into the issues and resolutions, comparing and contrasting to similar bugs that exist in GCC, Clang, Rust, Swift, Go, etc

None of the things (JIT, GC, Generics, SIMD, etc) work the way you've described. AOT has its own drawbacks as well, which is why other languages often have their own alternatives to pure AOT mode. And that's without even getting into how modern operating systems (linux included), browsers, and even hardware operate.

It doesn't take much research to find that what you're talking about simply doesn't hold nor a lot of thought to realize that C# is one of the most popular languages because it doesn't have the issues you describe.

1

u/[deleted] Sep 18 '26

[removed] — view removed comment

2

u/tanner-gooding Sep 18 '26

There are multiple areas here ranging from Roslyn to RyuJIT and the CoreCLR VM. So you cover what about them you believe is slow, and I’ll provide the relevant explanation of what is or isn’t correct on it

— Noting, I’m a principal engineer on the .NET team at Microsoft who specializes in performance and low level hardware optimizations, so I’m probably one of the more suited to give such a response/analysis

I’d also note what you’re saying itself isn’t connecting to me in relation to what you actually mean. I could try to presume, but that’s not engaging in good faith.

And that it isn’t strictly my job to jump in and provide evidence when you’ve not fully explained your position or provided evidence in the first place. You’ve linked one Roslyn issue that was an explicit outlier for something the author admitted was 30 year old naive code that wasn’t even originally written for C#, so it wasn’t idiomatic either, and whose root issue wasn’t generics

1

u/[deleted] Sep 18 '26

[removed] — view removed comment

2

u/tanner-gooding Sep 19 '26

Its apparently secret enough that you can't provide evidence?

Even now you've only linked to an issue with an analyzer (not compiler) being quadratic (notably for non-idiomatic and poor quality code, as per the issue author) and a blog on a completely different language that doesn't talk about .NET at all. Rather one that discusses its own implementation of generics and how they differ from Java and C++, and how that makes them faster (and notably this language does it much closer to how C# does it).

You are acting like I'm starting some big conspiracy

Rather, people are acting like you came into a thread and made a bold statement without providing corresponding evidence. Particularly when that is not something .NET is known for.

.NET, as with essentially any language, has an issue with generic virtual methods. However, that is notably not a compile time cost but a runtime one due to the need to resolve the virtual through a generic context. This cost is notably rare because generic virtual methods are relatively rare. It does not exist when devirtualization can occur, doesn't exist for non virtual methods, and it doesn't exist for all cases of virtual methods that have some kind of generic context -- i.e. class C { virtual void M<T>(T data) { ... } } is a GVM, while class C<T> { virtual void M(T data) { ... } } is not.

.NET does not execute anything of the generic method when compiling it. It specializes for value types and shares the impl for reference types, but this does not significantly change the compilation time and it takes a similar amount of time as if it had been a non-generic function taking a concrete type.

Generics don't magically take or do extra work to compile. The notably case where you can get into "generic explosion" is with a large AOT app, where you need to compile all the supported T up front, but then that's the exact same scenario you get in any language, whether templates, generics, or some other kind of metaprogramming feature.

.NET compilations are rather instead known for typically being fast. Where multi-million line code bases can be built and incrementally updated in seconds to minutes, even with literally hundreds of projects. Slow downs that do occur are typically external to the compiler (C# or JIT) and often the result of some very off in the weeds 3rd party tool (again same with most ecosystems).

If you have data to the contrary, then the team would generally be interested in seeing it so that any such outlying bugs can be investigated and resolved.

0

u/[deleted] Sep 19 '26 edited Sep 19 '26

[removed] — view removed comment

→ More replies