-
Notifications
You must be signed in to change notification settings - Fork 7
Description
Just if anyone goes for memory efficiency and allocation cautiousness
the implementation here for array memory pool is ineffective as it is using
ArrayPool<byte>.Create()
which actually uses ConfigurableArrayPool that has internal limitation of 1024 * 1024 (1MB) max array size
so in fact
_writeBuffer.Rent(AppendBlobBlockSize); _writeBuffer.Return(writeBuffer);
will actually allocate new array and returning it back to the pool does nothing, it is actually discarded.
as private const int AppendBlobBlockSize = 4_194_304; //4MB size is larger than that.
I would recommend MemoryPool for PipeLine as it can be copied to a memory span, and for incoming Stream buffer size of 81920 bytes (for obvious reasons) or an array buffer just below LOH byte limit (84 * 1024).
Which can be written into a memory stream (use RecyclableMemoryStream if possible) on size of the AppendBlobBlockSize threshold you need.