Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

ByteBuffer - Reduce Allocations for Serialization Path

オープン
#141 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
45/100
issue の種類
リファクタリング
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
csharp
領域
performance

調査の方向性

Start in Utilities/ByteBuffer.cs by inspecting PutInt, PutLong, GetInt, and GetLong, then review how the buffer manages its internal storage. Compare before and after allocation behavior using benchmark results. Done means the serialization paths avoid the described per-call allocations and supporting before/after benchmarks are provided; the optional Memory or Span refactor is broader scope.

索引モデルが issue の本文から書いたものです。

説明

agent enhancement

File: Utilities/ByteBuffer.cs

PutInt and PutLong both call BitConverter.GetBytes(...) which allocates a new byte[] on every call, then immediately Array.Copy it into the buffer. This is avoidable entirely using BinaryPrimitives and MemoryMarshal from System.Buffers:

// BEFORE - allocates byte[] every call
public void PutLong(long value)
{
    var longAsBytes = BitConverter.GetBytes(IPAddress.NetworkToHostOrder(value));
    Array.Copy(longAsBytes, 0, _internalBuffer, Position, longAsBytes.Length);
    Position += longAsBytes.Length;
}

// AFTER - zero allocation
public void PutLong(long value)
{
BinaryPrimitives.WriteInt64BigEndian(_internalBuffer.AsSpan(Position), value);
Position += sizeof(long);
}

public long GetLong()
{
var result = BinaryPrimitives.ReadInt64BigEndian(_internalBuffer.AsSpan(Position));
Position += sizeof(long);
return result;
}

The IPAddress.HostToNetworkOrder / NetworkToHostOrder dance exists solely to handle big-endian byte ordering — BinaryPrimitives.WriteInt64BigEndian does this directly, with no allocation. This applies equally to PutInt/GetInt. On serialization-heavy workloads this is high-impact.

The ByteBuffer itself could also be refactored to work over Memory<byte> or Span<byte> to allow callers to supply pooled or stack-allocated memory rather than always allocating internally.


Any pull requests addressing this change should provide supporting before and after benchmark results.

主要言語
C#
スター
185
フォーク
31
PR マージ指標
30日以内にマージされた PR はありません

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

HdrHistogram/HdrHistogram.NET のほかの issue

HdrHistogram/HdrHistogram.NET の issue をすべて見る

似ている issue

C# の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。