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

LongConcurrentHistogram.IncrementCountAtIndex — Two Atomic Operations Where One Suffices

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

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

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
25/100
issue の種類
リファクタリング
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
csharp
領域
performance

調査の方向性

Start in LongConcurrentHistogram.cs at IncrementCountAtIndex and inspect TotalCount, including its Interlocked.Read usage. Compare the Java original and the mentioned Recorder pattern to understand the alternatives. Done means selecting and validating one approach for reducing recording atomic operations without breaking count correctness.

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

説明

agent enhancement

File: LongConcurrentHistogram.cs

protected override void IncrementCountAtIndex(int index)
{
    long criticalValue = _wrp.WriterCriticalSectionEnter();
    try
    {
        _counts.IncrementAndGet(index);      // Interlocked.Add
        Interlocked.Increment(ref _totalCount); // second atomic op
    }
    finally { _wrp.WriterCriticalSectionExit(criticalValue); }
}

Every RecordValue call in the concurrent histogram pays for WriterCriticalSectionEnter (an Interlocked.Increment), Interlocked.Add on the count, Interlocked.Increment on _totalCount, and WriterCriticalSectionExit (another Interlocked.Increment). That's four atomic operations per record.

_totalCount is only read by TotalCount which already calls Interlocked.Read. Consider whether _totalCount needs to be updated atomically at all during recording, or whether it can be derived lazily by summing the array (expensive) or maintained with a Volatile.Write (cheaper). The Java original avoids this cost by using a single updater CAS. A Recorder-pattern approach (per-thread histograms merged on read) avoids the issue entirely and is the recommended usage pattern anyway.

主要言語
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 を短くまとめたダイジェスト。