Skip to main content

Benchmarks

Synapse is built for low latency and low allocations on the hot path. This page compares it against two popular in-process mediators:

All three run the same scenarios from a single BenchmarkDotNet suite in benchmarks/SynapseBenchmark. Numbers are reproducible — see Running the benchmarks below.

note

Benchmarks measure dispatch overhead only — handlers are no-ops (a sum, or Task.CompletedTask). Real applications are dominated by handler work (I/O, DB), so these differences matter most in high-throughput, fan-out, or allocation-sensitive paths.

Environment

BenchmarkDotNet v0.15.8, macOS Tahoe 26.5.2 [Darwin 25.5.0]
Apple M5 Pro, 18 logical / 18 physical cores
.NET SDK 10.0.301, .NET 10.0.9, Arm64 RyuJIT

Lifetimes: Synapse and MediatR use their defaults; Mediator is registered as Transient to mirror MediatR's transient handlers for an apples-to-apples DI cost. Mediator's recommended Singleton lifetime would lower its numbers further.

Results

Lower is better. Ratio is relative to Synapse (baseline 1.00); Alloc is bytes allocated per operation.

Send — request with response

LibraryMeanRatioAllocated
Mediator17.3 ns0.8188 B
Synapse21.4 ns1.0072 B
MediatR27.7 ns1.30200 B
Synapse (direct handler)6.8 ns0.3272 B

Send — request without response (void)

LibraryMeanRatioAllocated
Synapse18.1 ns1.000 B
Mediator20.2 ns1.1288 B
MediatR30.6 ns1.69128 B
Synapse (direct handler)3.6 ns0.200 B

Synapse allocates zero bytes dispatching a void request.

Publish — one event, 5 handlers

LibraryMeanRatioAllocated
Mediator79.8 ns0.61184 B
Synapse130.4 ns1.00520 B
MediatR358.6 ns2.752088 B

Mediator's source-generated fan-out leads here; both beat MediatR by a wide margin.

Pipeline — request through 1 behavior

LibraryMeanRatioAllocated
Synapse22.7 ns1.0072 B
Mediator28.6 ns1.26240 B
MediatR57.7 ns2.54440 B

Pipeline — request through 3 behaviors

LibraryMeanRatioAllocated
Synapse26.2 ns1.0072 B
Mediator53.4 ns2.04496 B
MediatR89.7 ns3.43728 B

Synapse's pipeline allocation stays flat at 72 B regardless of behavior count, thanks to its cached, pre-composed delegate chain — competitors grow per added behavior.

Takeaways

  • Pipelines — Synapse is fastest and flat-allocating; the gap widens as behaviors stack.
  • Send (response) — Mediator edges ahead on raw speed; Synapse allocates less.
  • Send (void) — Synapse beats Mediator (18.1 vs 20.2 ns) and allocates nothing.
  • Publish — Mediator's generated fan-out wins; Synapse is ~2.75× faster than MediatR.
  • All three vastly outperform reflection-based MediatR on both time and allocations.

Pick based on your workload: pipeline-heavy / allocation-sensitive favors Synapse; raw publish throughput favors Mediator.

Running the benchmarks

cd benchmarks/SynapseBenchmark
dotnet run -c Release # full suite, all libraries
dotnet run -c Release -- --filter '*Pipeline*' # one category

The suite lives in a single class, SynapseVsMediatorsBenchmarks. Results land in BenchmarkDotNet.Artifacts/results/.