r/csharp • • 5d ago

Blog Top .NET 11 RPC libraries vs 26 gRPC libraries from an updated grpc_bench (Rust, Go, Java, C++)

https://fusion.actuallab.net/posts/261116-grpc-bench

Disclaimer: I am the author of ActualLab.Rpc and its RpcBenchmark, so I am not a neutral party. But the code is open source, and I welcome you to read it, run it, or evaluate with your AI agent.

I did my best to make the comparison fair - you can read about this in "Important Remarks" section.

13 Upvotes

16 comments sorted by

4

u/hez2010 4d ago

Currently .NET 11 is suffering from a thread-pool scheduling issue that can affects performance dramatically. I think this will be fixed in near future and you might want to retest it at that time.

1

u/alexyakunin 4d ago edited 4d ago

I am unaware of TP issues on .NET 11, but there is a big one affecting SignalR + likely, any HTTP, see ".NET 11 Pipe Scheduler Fix" section in "Important Details".

The tests already contain a workaround making it work like on .NET 10 - I run these benchmarks for a while & delta on .NET 11 was too big to disregard, so I found the cause.

When this fix is disabled, SignalR perf drops by 6x or so there; it slightly affects gRPC tests as well.

3

u/Praemont 4d ago

I considered using ActualLab.Rpc at one point, but the sheer number of transitive dependencie MessagePack, Newtonsoft.Json, CommunityToolkit, Reactive etc put me off. I doubt achieving NativeAOT compatibility would be straightforward with such a dependency stack.

1

u/alexyakunin 4d ago edited 4d ago

There is even a sample called exactly like that - NativeAot :) It runs RPC + Fusion over the local channel, but that's because Kestrel (websocket support there) isn't fully compatible with Native AOT.

Overall, NativeAot works perfectly fine there, if we're talking about client-side code. Server-side part is mostly dependent on Kestrel.

Though what's more important is that now you don't really need NativeAot - CoreCLR + R2R based on .mibc is a WAY better option for client-side apps. Same perf, but no restrictions + 2-3x smaller size.

2

u/Praemont 4d ago edited 4d ago

My point is that there are 163 trimming warnings. That doesn't necessarily mean it won't work under NativeAOT. I actually found the example you mentioned, and yes, it works. But you still have to be careful about which features you use, because not everything is AOT-compatible. For example, https://pastebin.com/GnX3mYsK this won't. You need to understand which serializers and other features might cause problems. For instance, Newtonsoft.Json isn't generally AOT-friendly.

This is why I prefer libraries to be modular, with separate packages like:

  • ActualLab.Fusion.Format.MessagePack
  • ActualLab.Fusion.Format.NewtonsoftJson
  • ActualLab.Fusion.Format.SystemTextJson
  • ActualLab.Fusion.Rpc.DependencyInjection (someone might want to use a different DI container instead of having Microsoft DI built in)

That way, each module could clearly indicate whether it's IsAotCompatible, and users could choose only the dependencies and features they actually need.

Hope that makes sense.

1

u/alexyakunin 4d ago edited 4d ago

Thanks for the very constructive feedback. You’re right about the dependencies, and I think it’s time to revisit them - I'm on it now, actually :). I expect I can remove or separate out most of the ones you mentioned.

I’ll address your specific example in a follow-up comment. Walking through it will also illustrate some of my broader concerns with NativeAOT. First, though, the dependencies:

The serializer dependencies are there because Fusion and ActualLab.Rpc have their own infrastructure types—messages, shared value types, etc.—that need to be serializable with whichever format you choose. When I originally implemented this, putting serialization attributes directly on those types was the simplest approach. But that also ties the assemblies defining them to the serializers.

I think at least MemoryPack and Newtonsoft.Json support can move into separate packages. There’s already a precedent: ActualLab.Serialization.NerdbankMessagePack. The serializers used most heavily are still built in, but the same package structure makes sense for them too.

The awkward part is replacing attribute-based integration and, in MemoryPack’s case, serializers generated alongside the types. One option is to implement and register the necessary formatters in the separate integration packages. That’s tedious code I was reluctant to write and maintain before. With Claude helping do the mechanical work, it’s a much more reasonable option now.

CommunityToolkit.HighPerformance should also be relatively straightforward to remove: I only use a small part of it, so I can bring the helpers I need into the library.

System.Reactive is less clear-cut. The main reason it’s there is Unit type, which is used throughout the APIs. Removing that dependency would mean introducing another version Unit type, and I’m not sure that would make things less confusing for users. I need to think about that tradeoff a bit more.

1

u/alexyakunin 4d ago

On NativeAOT itself: I’ve spent more time dealing with this than I ever wanted to. We’ve tried pretty much every combination of AOT, JIT, and interpretation available across Mono and CoreCLR while building Voxt.

For a rather painful example, see my post about Mono AOT. We found thousands of methods falling back to JIT during startup, including ordinary async machinery and generic methods involving value types—even when explicitly included in an AOT profile. Microsoft confirmed the underlying limitation, but said a proper fix would require changes too extensive for .NET 9. When we later asked for updates, the response pointed to NativeAOT work on Android, with no timeline. I also wrote up my broader concerns about the deployment models here.

As for the NativeAOT, my biggest concern is the combination of generic code expansion and the requirement to identify everything ahead of time. Value-type generic instantiations need specialized native code. When reflection enters the picture, making sure every required instantiation is available becomes considerably harder. Preserving more code can help with coverage, but it also increases binary size and compilation time.

In our experiments with Voxt, the size increase was substantial—from memory, roughly 3–4× for the compiled code, though I’d want to rerun the comparison before presenting that as a benchmark. Compilation also became painfully slow. Add the restrictions on reflection and runtime code generation, and that is a lot of engineering work for a deployment choice.

This is why I'm 100% for CoreCLR + profile-guided ReadyToRun - that's exactly what we use now. Record a representative startup, precompile the methods it actually uses, and keep JIT available for everything else. You can remove most startup JIT work without precompiling every possible execution path. That gives you a useful balance between startup time, application size, and compatibility. Microsoft’s current mobile runtime model supports precisely this direction.

On iOS, the interpreter provides the fallback instead of JIT. If the profile covers the statically identifiable paths + PGO-driven ones, and interpretation handles the rest, which is relatively infrequent, that’s a tradeoff I’m happy to make; a profile miss becomes a performance issue you can measure and fix.

For a practical example, our iOS app starts in about 0.4 seconds on an iPhone 13 relying on CoreCLR+R2R, while issuing roughly 3,000 calls through ActualLab.Rpc. Fusion’s speculative execution with a persistent cache lets those calls return cached results immediately, so application logic and UI rendering can proceed while the server validates them in the background - i.e., these 3K calls are sent during that period, but not all of them have a chance to complete (which is still impressive - and that's one of reasons ActualLab.Rpc exists). But overall, you don’t need NativeAOT to get that kind of startup time, even on iOS.

So what's remaining for NativeAOT?

For any long-running servers, NativeAOT is impossible to justify:
- Startup is amortized over the process lifetime
- Steady-state performance is worse.
- But the time you'll end up spending to support it in any relatively large app is huge.

I assume there are server workloads where cold starts or memory density may make the tradeoff worthwhile, but... I can't name a single one.

There are clearer uses for NativeAOT in short-lived command-line tools, native libraries, and workloads where every cold start matters. But that's a fairly niche case I'd define ~ as "toy console or on-device apps". The bigger question here is whether .NET itself is a good choice for it, assuming you can translate such apps to Rust in a matter of hours.

A general fallback for value-type generics would change part of that equation. But Microsoft has explicitly said that universal shared generics aren’t part of the NativeAOT plan, and recommends JIT or interpretation for scenarios that need that flexibility. That’s essentially the direction I prefer too.

None of this makes your point about the warnings invalid. It explains why I recommend looking at CoreCLR + profile-guided R2R variant as an alternative.

2

u/Praemont 3d ago

On server side the R2R is enough, though I see more people wanting to use NativeAOT on servers too, especially for IoT. Even Orleans seems to be moving towards NativeAOT in the future.

Personally, I only need NativeAOT support on the client side. I have a huge desktop app with Avalonia as the host, Blazor Hybrid for the UI (using WebView bindings that support NativeAOT, unlike the ones Microsoft provides), and SignalR since it's more of a thin client.

That's why I've been looking into RPC libraries. What I like about NativeAOT is the smaller app size, no need to install the .NET runtime, lower memory usage, and better performance. All of that matters quite a bit since we use low-end PCs for our PoS systems.

Soon the Mono AOT issues should be gone, as everything will be running on CoreCLR. Btw, if you haven't already, I really recommend switching to MTPv2 for tests using xunit.v3.aot. You can use the same test suite for both JIT and NativeAOT. If you need examples, I can provide some.

Unit type

I think it's fine if you create own primitive, many libs do including MediatR and MagicOnion

1

u/alexyakunin 1d ago edited 1d ago

Btw, spent most of weekend to get rid of a fair number of dependencies. The result: https://fusion.actuallab.net/Migration/To-v16

I.e., now it's a few framework libraries + ZString + MessagePack.

As for NativeAOT sample, it produces zero warnings now - thanks to the new code generator that roots MessagePack and STJ formatters for types involved in RPC.

Earlier this step was supposed to be manual (serialization libs are kind of out of scope).

1

u/alexyakunin 1d ago

I didn't quite get the point on Avalonia host with Blazor Hybrid. It was phrased like it's a huge Avalonia app... And a Blazor Hybrid app? Do you use Avalonia mostly to host Blazor?

Also, you've mentioned that it should run on fairly low end PCs - but probably it's still something like 4 megabytes of RAM? I never thought that the low end for the PC might be a consideration to use native AOT - low end phones is something I would weigh in, but not PCs...

We ship the app as CoreCLR plus R2R, and it MAUI wrapper + Blazor Hybrid app. I tried NativeAot builds too, and funny enough, they were slightly slower even to start - compared to R2R (~0.1-0.2s slower) + the app size was definitely larger. As for the sustained perf, CoreCLR is unbeatable, but in our case this isn't noticeable - the perf is not a concern on the client.

Curious what's the real delta between our cases.

1

u/alexyakunin 4d ago

About your example: I built it with NativeAOT (.NET 11, Fusion 15.1.62). You're right, it fails. Ping works, but Count(ApiArray<Status>) throws:

NotSupportedException: 'ActualLab.Api.Internal.ApiArrayMessagePackFormatter`1[Status]' is missing native code or metadata

Two lines fix it:

CodeKeeper.Keep<ApiArrayMessagePackFormatter<Status>>();
CodeKeeper.Keep<MessagePack.Formatters.GenericEnumFormatter<Status>>();

The real point isn't ApiArray<T>, though. As soon as you use your own types with custom formatters, you can't expect the framework or the serializer to handle NativeAOT for you. Nobody but you knows which formatter instantiations your app needs.

ApiArray<T> is a good illustration. It's an immutable array type used in Fusion API contracts, with methods like With, Without and WithOrUpdate that return modified copies. That's why it needs a custom formatter, declared as [MessagePackFormatter(typeof(ApiArrayMessagePackFormatter<>))]. At run time MessagePack reads that attribute, calls MakeGenericType with the actual T, and creates the formatter through Activator.CreateInstance. Enums go through the same steps. With a value-type T, each instantiation needs its own native code. The AOT compiler has to know about it at compile time, and it can't: all it sees is code that turns a type from an attribute into an object, for whatever T arrives.

Fusion can't fix this for you either. A module initializer can only list types Fusion knows about, and there is no way to write "keep this for any T". Fusion's own module initializer does keep formatters for its internal types. Its generated RPC proxies also call KeepSerializable<TArg> and KeepSerializable<TResult> for every method, so KeepSerializable<ApiArray<Status>>() in your sample was redundant. But that only keeps what the method signature shows statically: the types and the generic Serialize<T>/Deserialize<T> paths. Which formatters actually get used depends on the serializer, its resolvers and the attributes it honors, and part of that is only decided at run time.

So this isn't specific to Fusion or ApiArray. Custom formatters for immutable types, wrappers and generic value types are common, and any serializer that finds formatters through reflection breaks the same way under NativeAOT. The only fix is to add the static dependency yourself, the way I did above.

On the warnings: trimming and AOT analysis is very verbose. That's useful, because the warnings in MessagePack's resolvers (IL2055, IL2067, IL2070, IL3050) point at exactly the code that broke here. But many warnings are false positives for a given app, and deciding which ones to suppress is your job. Fusion does this internally too: CodeKeeper is full of [UnconditionalSuppressMessage]. So the raw warning count tells you how much analysis work there is, not how much will break.

2

u/alexyakunin 5d ago edited 4d ago

Any questions are welcome.

P.S. Thanks for anyone who asked!

2

u/Dunge 4d ago

I wonder why the native aot version is slower than the normal dotnet version? Isn't it supposed to be faster?

Also why only have a "single threaded" version of the nodejs grpc test?

1

u/alexyakunin 4d ago

Yes, NativeAOT is supposed to be slower, mostly due to PGO in JIT.

1

u/alexyakunin 4d ago

Sorry, just read that:
- Also why only have a "single threaded" version of the nodejs grpc test?

Because NodeJS is single-threaded, I guess... And that's how the test was originally written in grpc_bench.

I am sure you can test it in multi-process mode, which requires some reverse proxy/load balancer in front of NodeJS processes. But this is out of scope of this test.

You can also extrapolate the existing results to that scenario: the max perf you can expect to get with N processes is (N * one_process_rps / load_balancing_cost), so it's 4*59K ~= 236K calls/s, which is still way worse than for any of top competitors.

2

u/zigzag312 4d ago

JIT has PGO, AOT doesn't