NServiceBus
NServiceBus copied to clipboard
Reduce memory allocations by using memory pooling
This issue was transferred from a private repository
Memory pooling can be applied to reduce the amount of memory allocations which results in more efficient memory and CPU utilization due to a reduction in garbage collector pauses and memory cleanup. Most noticeable areas would be the memory management of buffers for byte arrays and streams used for message (de)serialization of message bodies and for some transports headers or messages envelopes. Memory pooling could be achieved using RecyclableMemoryStream and MemoryStream from Microsoft.Toolkit.HighPerformance.Streams or potentially a custom solution that fits the processing pipeline.
Memory pooling is not a magic bullet. Here is a list of related topics to analyze:
- Pooling of streams (supporting expansion) vs arrays (fixed length)
- Pooling opt-in/opt-out, auto
- Lifetime management of pooled resources by the transport, core, or message serializer