Skip to content

Replace Microsoft.Extensions.ObjectPool with built-in Roslyn-based pool#55

Merged
jeffijoe merged 1 commit intomasterfrom
perf/pool
Feb 23, 2026
Merged

Replace Microsoft.Extensions.ObjectPool with built-in Roslyn-based pool#55
jeffijoe merged 1 commit intomasterfrom
perf/pool

Conversation

@jeffijoe
Copy link
Owner

@jeffijoe jeffijoe commented Feb 23, 2026

Performance results

Single-threaded

Pool Time
Roslyn-based ~9.1-9.2 μs
MS Pool ~13.4-13.5 μs
Improvement ~47% faster

Multi-threaded

Threads Roslyn-based MS Pool Speedup
1 17.9 μs 23.4 μs 1.3x
2 67.7 μs 120.5 μs 1.8x
4 187.9 μs 418.3 μs 2.2x
8 452.9 μs 1,471.1 μs 3.2x

Downstream performance improvements (formatting)

  • Single-threaded: 3-5% faster consistently
  • 8 threads: ~1.7x faster

Trade-off

The Roslyn-based pool allocates more under heavy contention (181 KB vs 783 B at 8 threads) because the lock-free CAS approach falls back to the factory on failed compare-and-swap. But these are short-lived Gen0 allocations that are cheap to GC, a worthwhile trade for the throughput gains for regular workloads.

…pool

This may allocate more during heavy contention, but is ~50% faster overall
@jeffijoe jeffijoe merged commit dae6f0b into master Feb 23, 2026
1 check passed
@jeffijoe jeffijoe deleted the perf/pool branch February 23, 2026 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant