Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

LongConcurrentHistogram.IncrementCountAtIndex — Two Atomic Operations Where One Suffices

Abierto
#148 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
25/100
Tipo de issue
Refactorización
Claridad
Necesita aclaración
Estado de actividad
Estancado
Stack tecnológico
csharp
Área
performance

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
C#
Estrellas
185
Forks
31
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de HdrHistogram/HdrHistogram.NET

Todos los issues de HdrHistogram/HdrHistogram.NET

Issues similares

Más issues de C#

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.