Module buffer_pool

Module buffer_pool 

Source
Expand description

Buffer pooling for message serialization/deserialization.

This module provides a thread-local buffer pool to reduce allocation overhead for message processing. Buffers are reused for messages under a size threshold, while larger messages get fresh allocations.

§Performance

  • Small messages (< 64KB): Reused from pool, zero allocation
  • Large messages (>= 64KB): Fresh allocation (rare case)
  • Thread-local: No contention between threads

Structs§

PoolStats
Buffer pool statistics.
PooledBuffer
A pooled buffer that returns to the pool on drop.

Constants§

DEFAULT_BUFFER_SIZE
Default buffer size (64 KB).
MAX_POOLED_BUFFER_SIZE
Maximum buffer size to pool (larger buffers are dropped).
MAX_POOL_SIZE
Maximum number of buffers to keep in the pool per thread.

Functions§

acquire
Acquire a buffer from the pool with the given minimum capacity.
acquire_default
Acquire a buffer with the default size.
clear_pool
Clear the buffer pool for the current thread.
pool_stats
Get buffer pool statistics for the current thread.