HPC C#

HPC C# (Hardcore Mode)

Did you know C# has a hardcore mode that rivals C++ and Rust performance? Discover the 5 features that make it possible—and why Go can't keep up.

By Robert Long | January 5, 2025

Did you know there is a niche language out there that gives you the performance of C++ & Rust, but also provides the rich, high-level features of Java, Go, Python, and Node.js?

Sounds too good to be true? It's true!

This language tackles high-performance computing in 5 brilliant ways:


1. Challenging the Immutability Dogma

In high-performance systems, immutability can be very expensive. Every time you modify a reference type on the heap in Java or Node.js, it often forces you to clone that chunk of data.

This language solves the problem with a concept called Span<T> (aka sliding window or slice for Rust and Go devs). It allows you to point to a place in memory and tell it exactly what part you want to see—start and end—without cloning that data over and over.

You get pointer arithmetic without the dangerous unsafe memory access.

2. Real Structs (Value Types)

When you use a struct, the data is a Value Type. It's stored inline—whether on the stack for local variables, or embedded directly in an array or class—without pointer indirection or its own GC tracking overhead.

This eliminates the "pointer chasing" that kills cache performance in languages where every object is a separate heap allocation. In this language, a Node[1000] array of structs is one contiguous block of memory, not 1000 scattered heap objects.

Java has primitives, but it still cannot create "custom" value types on the stack (Project Valhalla has been "coming soon" for years). Go has structs, but escape analysis often moves them to the heap anyway—you can't guarantee stack placement.

3. Adopted a Borrow Checker

Rust made waves with its no-GC memory model. Recently, this language introduced a mechanism that is very similar (scoped), guaranteeing memory safety and lifetime management at compile time for stack-allocated types like Span<T>.

4. Direct Memory Control Mode

This mode allows for direct access to memory addresses (identical to C) for specific tasks when you need absolute control—supported from day 1.

5. Native AOT Compilation

C# now supports Ahead-of-Time (AOT) compilation, producing true native binaries without requiring the .NET runtime to be installed.

The advantages are significant:

  • Instant startup — No JIT warm-up, the app starts immediately
  • Smaller footprint — Aggressive trimming removes unused code, keeping binaries lean
  • Self-contained binary — Single executable, no runtime dependencies
  • HPC synergy — When combined with structs, Span<T>, and no-GC patterns, AOT-compiled code runs at maximum efficiency with zero runtime overhead

This makes C# viable for scenarios previously reserved for C/C++/Rust: embedded systems, CLI tools, serverless cold starts, and performance-critical microservices.


The Big Reveal

If you haven't figured it out by now, the language I'm talking about is C#.

Yes, C# has a hardcore mode. In recent years, it has been silently rewriting the standard libraries using the 5 features mentioned earlier. Benchmarks now show it consistently beating Java, Go, and Node.js by huge margins—and in many cases, performing neck-and-neck with C++, C, and Rust (often within 5-10%).

But Wait—What About Go?

Go is often praised for its simplicity and performance. It has structs, it compiles to native code, and its goroutines are lightweight. Shouldn't it be in the same league as C#?

Here's Go's Achilles' heel: escape analysis. When you create a struct in Go, the compiler tries to figure out if it can stay on the stack. But if the struct is returned, passed to another goroutine, or its pointer escapes in any way—it gets moved to the heap. You have no explicit control.

Worse, Go's "growable stacks" for goroutines mean stack memory is actually heap-allocated. When a goroutine's stack grows, Go allocates new heap memory and copies the entire stack over. This "copy-on-grow" behavior adds overhead that C# avoids entirely.

The result? Go sits in an awkward middle ground: faster than Java/Python, but unable to match HPC C# because it lacks the low-level control over memory placement that structs and Span<T> provide.


The Results

If you look at the TechEmpower Benchmarks (the industry standard for web speed), the shift happened around 2020. Today, ASP.NET Core consistently ranks in the Top 10 globally—beating out Go and Node.js by significant margins and trading blows with Rust and C++ implementations.

Benchmark Comparisons
  • C# vs. Node.js: Outranks Node by margins often exceeding 400%
  • C# vs. Go & Java: Consistently beats standard Go and Java implementations by 40-50% in raw throughput
  • C# vs. Rust: Now trading blows. While Rust (Actix) often holds #1 (~7.2M RPS), C# (ASP.NET Core) is right behind (~7.0M RPS). The gap is now so small (within 5%) that for business applications, they are effectively the same speed.

What Makes C# Unique

Programming languages have traditionally fallen into two camps: performance languages (C, C++, Rust) that give you speed but demand manual memory management and steep learning curves, or productivity languages (Java, Node.js, Python) that are easy to use but leave you at the mercy of the garbage collector with no low-level control.

C# breaks this paradigm. It's the only mainstream language that genuinely bridges both worlds:

Venn diagram showing C# bridging Performance languages (C, C++, Rust) and Productivity languages (Java, Node.js, Python)

On the left, you have C, C++, and Rust—blazingly fast, but with significant tradeoffs. No garbage collector means manual memory management (C/C++) or fighting the borrow checker (Rust). These languages are powerful but unforgiving.

On the right, you have Java, Go, Node.js, and Python—developer-friendly, but with hard limitations. No real structs that guarantee stack placement, no Span<T>, no direct memory access. Go tries to be clever with escape analysis, but complex data structures almost always end up on the heap. You're still at the mercy of the garbage collector and runtime decisions.

C# sits in the center. By default, it's as productive as Java or Python. But when you need performance, you flip into "hardcore mode"—using structs, Span<T>, scoped references, unsafe code, and Native AOT to achieve C/C++/Rust-level performance.

No language switch. No codebase rewrite. Same language, different mode.

The Cloud Computing Advantage

Why does this matter beyond bragging rights? Money.

In cloud computing, you pay for every CPU cycle. A 5x performance improvement means:

  • 5x lower compute costs — same workload, fewer resources
  • 5x better cold starts — critical for serverless and edge computing
  • 5x more headroom — handle traffic spikes without scaling

When you're running thousands of containers processing millions of requests, these margins compound. C# lets you develop with the productivity of Java, then optimize hot paths to cut your cloud bill by 80%—without rewriting your application in Rust or C++.


Keywords
Span<T> structs borrow checker unsafe TechEmpower ASP.NET Core high performance stack allocation AOT Native AOT ahead-of-time compilation Go escape analysis cloud computing

Related Articles

HPC C# Algorithms
Recursive DFS: 30 Million Stack Frames Deep

820% faster. 30 million stack frames. 2x deeper than standard C#, 1,500x deeper than Java/Python. This is what C# can really do.

About the Author

Robert Long
Robert Long

Senior Software Engineer

10+ years building cloud-native, high-performance software using first-principles thinking.