microsoft / microsoft/Microsoft.IO.RecyclableMemoryStream

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

Open
#339 5 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
2.2k
Forks
213
Avg merge
2d 44m
Merged PRs (30d)
14

Description

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: https://github.com/OPCFoundation/UA-.NETStandard/pull/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?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the benchmark results in OPCFoundation/UA-.NETStandard#2556, comparing BinaryEncoderRecyclableMemoryStream with BinaryEncoderArraySegmentStream and BinaryEncoderMemoryStream. Trace the Span-based Read and ReadOnlySpan-based Write paths in RecyclableMemoryStream and verify whether the benchmark exercises them. Done means identifying whether the benchmark is flawed or documenting the cause of the performance difference.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.