Benchmarks
Kevlar vs Polly v8 across every strategy, measured with BenchmarkDotNet on GitHub Actions and republished automatically by the benchmarks workflow.
Last updated 2026-11-10 05:44 UTC (commit 306a424).
Microbenchmarks on shared CI runners are noisy. The vs Polly column is the median ratio over the most recent runs (up to 10); anything within ±20% is reported as on par. Absolute times move with runner hardware — the ratios are the signal.
Pipeline overhead floor
What an empty pipeline costs per execution — the fixed tax every strategy builds on.
| Scenario | Kevlar | Polly | Kevlar allocated | Polly allocated | Kevlar vs Polly |
|---|---|---|---|---|---|
| Empty pipeline — async | 18.5 ns | 41.3 ns | 0 B | 0 B | 3.4× faster |
| Empty pipeline — reference-state baseline | 14.6 ns | — | 0 B | — | — |
| Empty pipeline — caller-seeded context | 65.5 ns | — | 0 B | — | — |
| EmptyOutcomeState | 10.0 ns | — | 0 B | — | — |
| EmptyTaskOutcomeState | 12.5 ns | — | 0 B | — | — |
| Empty pipeline — zero-closure state overload | 26.2 ns | 41.5 ns | 0 B | 0 B | 3.5× faster |
| Empty pipeline — sync | 9.6 ns | 29.8 ns | 0 B | 0 B | 3.4× faster |
| NestedEmptyAsync | 101 ns | — | 0 B | — | — |
| NestedEmptySync | 101 ns | — | 0 B | — | — |
| NestedWithPropertiesAsync | 149 ns | — | 0 B | — | — |
| NestedWithPropertiesSync | 155 ns | — | 0 B | — | — |
Retry
Happy path (judge overhead only) and a recovery path where every call fails twice before succeeding, with backoff disabled so only strategy machinery is measured.
| Scenario | Kevlar | Polly | Kevlar allocated | Polly allocated | Kevlar vs Polly |
|---|---|---|---|---|---|
| Retry(3) — success on first attempt | 138 ns | 238 ns | 0 B | 24 B | 2.0× faster |
| Retry(3) — two failures then success | 4.35 μs | 4.60 μs | 192 B | 328 B | on par |
Timeout
The timeout never fires; this is the cost of arming and disarming the cancellation plumbing on every call.
| Scenario | Kevlar | Polly | Kevlar allocated | Polly allocated | Kevlar vs Polly |
|---|---|---|---|---|---|
| Timeout(10 s) — completes instantly | 174 ns | 187 ns | 0 B | 0 B | 1.2× faster |
| SynchronousGenerator_HappyPath | 216 ns | — | 0 B | — | — |
| AsynchronousGenerator_HappyPath | 1.63 μs | — | 559 B | — | — |
| AsyncHookConfigured_HappyPath | 211 ns | — | 0 B | — | — |
Circuit breaker
Ratio/sampling bookkeeping while closed, and the fast-fail rejection cost while manually isolated — caught as a thrown exception, and read from the no-throw ExecuteOutcomeAsync API.
| Scenario | Kevlar | Polly | Kevlar allocated | Polly allocated | Kevlar vs Polly |
|---|---|---|---|---|---|
| Isolated circuit — fast-fail rejection thrown | 5.51 μs | 5.71 μs | 1.3 KB | 1.3 KB | on par |
| Isolated circuit — fast-fail rejection via ExecuteOutcomeAsync | 110 ns | 182 ns | 144 B | 200 B | 1.7× faster |
| Ratio breaker, closed — success | 178 ns | 243 ns | 0 B | 24 B | 1.5× faster |
| DynamicDurationConfigured | 233 ns | — | 0 B | — | — |
| AsyncCallbackConfigured | 208 ns | — | 0 B | — | — |
| SlowCallDetectionConfigured | 289 ns | — | 0 B | — | — |
Circuit breaker under contention
Eight workers share one open circuit, so every call is a fast-fail rejection observed as an outcome; this is the per-call cost during an outage.
| Scenario | Kevlar | Polly | Kevlar allocated | Polly allocated | Kevlar vs Polly |
|---|---|---|---|---|---|
| Open circuit — 8 workers rejected | 63.5 ns | 199 ns | 144 B | 200 B | 3.1× faster |
Fallback
Pass-through when the execution succeeds, and substitution when it throws.
| Scenario | Kevlar | Polly | Kevlar allocated | Polly allocated | Kevlar vs Polly |
|---|---|---|---|---|---|
| NoNotification | 2.50 μs | — | 200 B | — | — |
| CompletedAsyncNotification | 2.48 μs | — | 200 B | — | — |
| YieldingAsyncNotification | 6.52 μs | — | 807 B | — | — |
| Fallback — not triggered | 134 ns | 122 ns | 0 B | 0 B | on par |
| SynchronousDelegate_Triggered | 2.42 μs | — | 200 B | — | — |
| Fallback — triggered by exception | 2.56 μs | 2.56 μs | 200 B | 256 B | on par |
| EmptyVoid | 44.3 ns | — | 0 B | — | — |
| VoidPassThrough | 174 ns | — | 0 B | — | — |
Rate limit
Uncontended token-bucket permit acquisition — every call is admitted — and the rejection cost once the budget is exhausted, thrown vs ExecuteOutcomeAsync.
| Scenario | Kevlar | Polly | Kevlar allocated | Polly allocated | Kevlar vs Polly |
|---|---|---|---|---|---|
| Budget exhausted — rejection thrown | 5.60 μs | 69.61 μs | 1.3 KB | 41.4 KB | 12× faster |
| Budget exhausted — rejection via ExecuteOutcomeAsync | 150 ns | 46.04 μs | 136 B | 35.5 KB | 291× faster |
| Token bucket — uncontended acquire | 152 ns | 129 ns | 0 B | 0 B | on par |
| WithHooks_Uncontended | 155 ns | — | 0 B | — | — |
| FrameworkAdapter_Uncontended | 147 ns | — | 0 B | — | — |
| PartitionedFrameworkAdapter_Uncontended | 178 ns | — | 32 B | — | — |
Concurrency limit
A single caller against a large permit count; acquire/release cost with no queueing. The rejection rows hold the only permit and compare thrown vs ExecuteOutcomeAsync.
| Scenario | Kevlar | Polly | Kevlar allocated | Polly allocated | Kevlar vs Polly |
|---|---|---|---|---|---|
| Permits exhausted — rejection thrown | 5.54 μs | 64.31 μs | 1.3 KB | 39.5 KB | 11× faster |
| Permits exhausted — rejection via ExecuteOutcomeAsync | 99.2 ns | 42.09 μs | 136 B | 33.6 KB | 408× faster |
| Concurrency limit — uncontended | 149 ns | 172 ns | 0 B | 40 B | 1.4× faster |
| WithHooks_Uncontended | 153 ns | — | 0 B | — | — |
| Adaptive_Uncontended | 221 ns | — | 0 B | — | — |
Typed result handling
Retry configured to treat a sentinel result as a failure; the returned value never matches, so this is the per-call cost of judging results.
| Scenario | Kevlar | Polly | Kevlar allocated | Polly allocated | Kevlar vs Polly |
|---|---|---|---|---|---|
| Typed retry — result judged, no retry | 135 ns | 181 ns | 0 B | 0 B | 1.5× faster |
Composed pipelines
How per-call overhead scales with pipeline depth when nothing goes wrong.
| Scenario | Kevlar | Polly | Kevlar allocated | Polly allocated | Kevlar vs Polly |
|---|---|---|---|---|---|
| Timeout → Retry → ratio breaker | 338 ns | 671 ns | 0 B | 48 B | 1.9× faster |
| Token bucket → Timeout → Retry → ratio breaker → Concurrency limit | 487 ns | 942 ns | 0 B | 88 B | 2.0× faster |
| TokenBucketRatioFiveStrategyChainSync | 441 ns | 964 ns | 0 B | 88 B | 2.2× faster |
Environment
- AMD EPYC 7763
- .NET 10.0.14 (10.0.14, 10.0.1426.52326), BenchmarkDotNet 0.15.8
- Times are medians; allocations are per operation.
Reproduce
dotnet run -c Release --project benchmarks/Kevlar.Benchmarks -- --filter '*'
As always with microbenchmarks: measure your own workload before optimizing around these numbers. Nanosecond differences matter in tight loops and high-throughput services; they don't matter around a 50 ms network call.