Skip to content

perf: use native sync.Pool for connection freelists#192

Draft
kislaykishore wants to merge 1 commit intojacobsa:masterfrom
kislaykishore:sync-pool-perf
Draft

perf: use native sync.Pool for connection freelists#192
kislaykishore wants to merge 1 commit intojacobsa:masterfrom
kislaykishore:sync-pool-perf

Conversation

@kislaykishore
Copy link
Copy Markdown
Contributor

This PR replaces the custom lock-guarded freelist implementation for message buffers with native sync.Pool allocations, significantly reducing mutex contention and GC pressure.

Benchmark Results (16 CPUs)

Old Implementation (Custom Freelist + Mutex):

BenchmarkGetPutInMessage-16      6543512        182.5 ns/op
BenchmarkGetPutOutMessage-16     6632773        185.3 ns/op

New Implementation (sync.Pool):

BenchmarkGetPutInMessage-16    551016232          2.125 ns/op
BenchmarkGetPutOutMessage-16   531943348          2.231 ns/op

This represents an ~85x performance improvement for message buffer allocations under high concurrency. Note that sync.Pool also automatically reclaims memory during GC, preventing long-lived memory high-water marks.

This replaces the custom lock-guarded freelist implementation with native sync.Pool allocations for buffer.InMessage and buffer.OutMessage, significantly reducing mutex contention.

Benchmarks (16 CPUs):
Old (freelist + Mutex):
BenchmarkGetPutInMessage-16      6543512        182.5 ns/op
BenchmarkGetPutOutMessage-16     6632773        185.3 ns/op

New (sync.Pool):
BenchmarkGetPutInMessage-16    551016232          2.125 ns/op
BenchmarkGetPutOutMessage-16   531943348          2.231 ns/op

Performance improved by ~85x under high concurrency.
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