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.6 (25G72) [Darwin 25.6.0]
Apple M5 Pro, 18 logical / 18 physical cores
.NET SDK 10.0.302, .NET 10.0.10, 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
Mediator18.6 ns0.8888 B
Synapse21.2 ns1.0072 B
MediatR28.4 ns1.34200 B
Synapse (direct handler)7.1 ns0.3372 B

Send — request without response (void)

LibraryMeanRatioAllocated
Synapse17.6 ns1.000 B
Mediator22.4 ns1.2788 B
MediatR30.2 ns1.71128 B
Synapse (direct handler)3.6 ns0.200 B

Synapse allocates zero bytes dispatching a void request.

Publish — one event, 5 handlers

LibraryMeanRatioAllocated
Mediator74.2 ns0.57184 B
Synapse130.6 ns1.00520 B
MediatR357.1 ns2.742088 B

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

Pipeline — request through 1 behavior

LibraryMeanRatioAllocated
Synapse22.0 ns1.0072 B
Mediator29.4 ns1.34240 B
MediatR58.6 ns2.66440 B

Pipeline — request through 3 behaviors

LibraryMeanRatioAllocated
Synapse26.3 ns1.0072 B
Mediator51.9 ns1.97496 B
MediatR89.3 ns3.40728 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 (17.6 vs 22.4 ns) and allocates nothing.
  • Publish — Mediator's generated fan-out wins; Synapse is ~2.74× 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/.