Skip to content

WriteBuffer ArrayPool is not effective and causes allocations #16

@krtek2k

Description

@krtek2k

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions