Skip to content

For many small stream writes, RecyclableMemoryStream is slower than other implementations #339

@mregen

Description

@mregen

For a project which implements its own buffered memory stream I added the int Read(Span<byte> buffer) and void Write(ReadOnlySpan<byte> buffer) signatures and compared the performance of MemoryStream, ArraySegmentStream (custom based on ArrayPool) and RecyclableMemoryStream.

To my surprise, RecyclableMemoryStream is always outperformed by MemoryStream and ArraySegmentStream by a factor of two, as if the Write(ReadOnlyMemory<byte>) is not properly implemented or disabled in RecyclableMemoryStream?

see benchmark results here: OPCFoundation/UA-.NETStandard#2556

see results of BinaryEncoderRecyclableMemoryStream vs BinaryEncoderArraySegmentStream and BinaryEncoderMemoryStream.

Any idea what could be wrong in the benchmark or why RecyclableMemoryStream.Write is always slower?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions