Object Pooling
Boost performance with MoroJS's built-in object pooling system. Reduce garbage collection pressure and improve throughput by reusing objects instead of creating new ones.
On this page
Performance That Scales
Object pooling reduces garbage collection overhead and memory allocation time by reusing objects instead of creating and destroying them repeatedly.
Performance Impact
Without Pooling
- • Requests/sec: 15,000
- • Avg latency: 6.5ms
- • GC time: 15% of CPU
- • Memory: 250MB
With Pooling
- • Requests/sec: 45,000 (+200%)
- • Avg latency: 2.2ms (-66%)
- • GC time: 3% of CPU (-80%)
- • Memory: 180MB (-28%)
Quick Example
Object Pooling in Action
typescript
Built-in Pools
Automatic Pooling
MoroJS automatically manages several object pools for common use cases:
Parameter Object Pool
Reuses objects for route parameters (req.params).
Query Object Pool
Reuses objects for query string parameters (req.query).
Buffer Pools
Reuses buffers for various sizes (64, 256, 1024, 4096, 16384 bytes).
Route & Response Cache
Caches route lookups and complete responses with LRU eviction.
Custom Pools
Creating Custom Object Pools
typescript
LRU Cache
typescript
Monitoring and Statistics
Global Statistics
typescript
Monitoring Endpoint
typescript
Adaptive Pool Sizing
typescript