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

ByteBuffer - Reduce Allocations for Serialization Path

Abierto
#141 1 comentario 0 reacciones 0 asignados Ver en GitHub

@LeeCampbell ya está trabajando en esto.

Desde el 24/3/2026.

  • #2 de @LeeCampbell — cerrado sin fusionar
  • #155 de @leecampbell-codeagent — cerrado sin fusionar
  • #165 de @LeeCampbell — abierto

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
45/100
Tipo de issue
Refactorización
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
csharp
Área
performance

Línea de trabajo

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.

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

Descripción

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.

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.