Add segmented buffering and sequence reads to `ArrayPoolBufferWriter<T>`
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 45/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- csharp
- 領域
- backend, performance
調査の方向性
Start by inspecting the existing ArrayPoolBufferWriter implementation, especially GetSpan(), GetMemory(), WrittenMemory, WrittenSpan, DangerousGetArray(), Clear(), and Dispose(). Compare the proposed segmented behavior with the feature/segmented-arraypoolbufferwriter branch. Done means adding GetReadOnlySequence(), retaining completed pooled arrays, consolidating contiguous views on demand, and returning all arrays during cleanup.
索引モデルが issue の本文から書いたものです。
説明
Overview
ArrayPoolBufferWriter<T> currently copies all written data into a new pooled array whenever it grows. With multiple writes and an unknown final size, those repeated copies consume memory bandwidth. Retaining completed arrays as segments would avoid copying earlier writes on each growth and let callers read the result as a ReadOnlySequence<T> without flattening it. Callers that need a contiguous buffer could still use the existing APIs, which would consolidate on demand.
API breakdown
namespace CommunityToolkit.HighPerformance.Buffers;
public sealed class ArrayPoolBufferWriter<T> : IBuffer<T>, IMemoryOwner<T>
{
public ReadOnlySequence<T> GetReadOnlySequence();
}
Existing public signatures remain unchanged. GetSpan() and GetMemory() write to the active segment; WrittenMemory, WrittenSpan, and DangerousGetArray() provide contiguous data through on-demand consolidation. Clear() and Dispose() return retained arrays to the pool. A returned sequence is valid only until the writer is modified, consolidated, cleared, or disposed.
Usage example
using ArrayPoolBufferWriter<byte> writer = new();
foreach (ReadOnlyMemory<byte> chunk in chunks)
{
chunk.Span.CopyTo(writer.GetSpan(chunk.Length));
writer.Advance(chunk.Length);
}
// Consume the segments while the writer still owns their pooled arrays.
foreach (ReadOnlyMemory<byte> segment in writer.GetReadOnlySequence())
{
destination.Write(segment.Span);
}
Breaking change?
I'm not sure
Alternatives
Keep the current contiguous writer and pay the copy cost on growth, or use Microsoft.IO.RecyclableMemoryStream where its MemoryStream-like API and pooling features are needed.
Additional context
This may be slower for some workloads. Segmentation adds buffer rents and metadata, while requesting a contiguous view still requires a copy. Small payloads and code that frequently accesses WrittenMemory or WrittenSpan should be benchmarked alongside append-heavy workloads.
Combined with other CommunityToolkit.HighPerformance memory and stream helpers, this might be a good alternative to Microsoft.IO.RecyclableMemoryStream for some append-and-read workloads. It would not be a drop-in replacement for that library’s seekable stream behavior, configurable pooling, or diagnostics. A proposed implementation is in feature/segmented-arraypoolbufferwriter.
Help us help you
Yes, I'd like to be assigned to work on this item
- 主要言語
- C#
- スター
- 3.8k
- フォーク
- 401
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
CommunityToolkit/dotnet のほかの issue
-
RelayCommand<T>.CanExecute(null) returns false for value types without a predicate対応中かも @apachezy が 84 日前に担当しました。 オープンbug :bug:
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
CommunityToolkit/dotnet#1206 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
CommunityToolkit/dotnet#1186 ·
-
bug :bug:
難易度 1/5 1時間未満 初心者へのやさしさ 68/100
CommunityToolkit/dotnet#648 ·
-
bug :bug:
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
CommunityToolkit/dotnet#1215 ·
-
IBufferWriterExtensions.Write : actively harmful対応中かも @mgravell が 65 日前に担当しました。 オープンbug :bug:
難易度 4/5 3〜5日 初心者へのやさしさ 58/100
CommunityToolkit/dotnet#1208 ·
CommunityToolkit/dotnet の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
Devolutions/UniGetUI#5541 ·
メンテナーはふだん 1 日以内に返信
-
agentic-workflows Needs: Triage :mag:
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
dette technique priorité: basse zone: service
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
damiensabau/nexus-lobby#25 ·