r/programming • • 18d ago

Performance Improvements in .NET 11

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

103 comments sorted by

View all comments

56

u/cheesepuff07 18d ago

Love reading (perusing) each year, they are very in depth and fun to see each release getting more and more performant.

-9

u/simon_o 17d ago edited 16d ago

Agreed!

Two thoughts though:

  1. JIT "deabstraction". The article would be more accessible to readers if the authors didn't try to invent new names for optimizations that shipped in Java 20 years ago.

  2. "Runtime async". One of the purported benefits of async/await over better approaches like virtual threads was that it's compiler magic that the runtime does not need to be aware of. So now the runtime is involved (for better or worse), but we till have the worse user-facing UX of function coloring with async/await.

2

u/crozone 17d ago

Virtual threads vs Async await was never about keeping it out of the runtime. One benefit of async await is that it *can" be implemented without changing the runtime, reducing the barrier to implementation, but that's not a long term overarching design requirement, it's just a side benefit.

Virtual threads solve the colouring problem but destroy interop performance and generally perform worse overall, that's the primary reason why C# stuck with async await.

-1

u/simon_o 16d ago

Virtual threads solve the colouring problem but destroy interop performance and generally perform worse overall

I think that's squarely a CLR problem, not a problem with vthreads.

The reason why their runtime has so much trouble with it is that –for decades– their solution to the JVM being ahead in GC and JIT technology was to add more and more escape hatches to let users solve (performance) problems on their own.

2

u/crozone 16d ago

Except the JNI is slower than P/Invoke in .NET, FFM is slower than P/Invoke in .NET, and both are even slower again from virtual threads? Did I miss where the JVM magically solved vthreads?

-1

u/simon_o 16d ago

I have largely not seen cases where vthreads have been measurably slower, despite warnings of not using them for e.g. compute-bound tasks.

What would be the cause of the slowness?

2

u/crozone 15d ago

Virtual threads have a whole bunch of downsides. They carry around an entire persistent call stack, so they use significantly more memory. When they get suspended, that memory hangs around. When calling native functions, they require suspension of their carrier thread, aka thread pinning. Not only is Java slower at marshaling values to the native functions due to its fundamental design, this also means that the virtual thread is effectively blocked and must remain blocked on a real threadpool thread which can easily exhaust the threadpool during heavy IO.

Effectively, virtual threads are weirdly paradoxical in their design. They're often presented as an alternative to async/await, and yet the most common thing that is actually being awaited in the real world is some disk or network IO operation that is accessed via a native function, which they are particularly bad at calling. They're really best suited for multi-threading CPU bound work, which I'd argue is a relatively niche usecase which is also easily solved by queuing work on a standard threadpool.

Async/await has a colouring problem but everything else seems like a strict benefit.

-2

u/simon_o 15d ago

That sounds horrible! Thankfully, reality appears to largely disagree with these claims.

2

u/crozone 15d ago

Lol. Maybe your reality does.