Add ArrayPoolBufferWriter<T>.ResetWrittenCount()
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 42/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bien especificado
- Estado de actividad
- Estancado
- Stack tecnológico
- csharp
- Área
- performance
Línea de trabajo
Localiza la implementación de ArrayPoolBufferWriter y sus pruebas existentes. Añade el comportamiento público de ResetWrittenCount() descrito en el issue, verifica que el recuento de elementos escritos se restablece sin borrar ni reemplazar el búfer del pool y ejecuta la suite de pruebas pertinente.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Overview
The System.Buffers.ArrayBufferWriter<T> class has a ResetWrittenCount method, which resets the write position to zero without clearing the buffer, thus allowing a writer to be reused without clearing the buffer. Without this method, we must create a new ArrayPoolBufferWriter<T> instance each time, which carries the GC overhead of allocating the new object, but also the overhead of returning the buffer to the pool, only to immediately get it back again.
API breakdown
namespace CommunityToolkit.HighPerformance.Buffers;
public sealed class ArrayPoolBufferWriter<T> : IBuffer<T>, IMemoryOwner<T>
{
public void ResetWrittenCount() => index = 0;
}
Usage example
using var buffer = new ArrayPoolBufferWriter<byte>();
using var jsonWriter = new Utf8JsonWriter(buffer);
for (var i = 0; i < 100; i++)
{
// Serialize JSON into buffer.
JsonSerializer.Serialize(jsonWriter, obj, _jsonOptions);
// Compress JSON into output buffer.
compressionStream.Write(buffer.WrittenSpan);
// Reset the JSON writer and buffer.
buffer.ResetWrittenCount();
jsonWriter.Reset();
}
Breaking change?
No
Alternatives
There is no way to reuse the buffer without incurring the cost of clearing the buffer or cycling the buffer through the array pool.
Additional context
No response
Help us help you
Yes, I'd like to be assigned to work on this item
- Lenguaje dominante
- C#
- Estrellas
- 3.8k
- Forks
- 401
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de CommunityToolkit/dotnet
-
bug :bug:
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
CommunityToolkit/dotnet#1206 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
CommunityToolkit/dotnet#1186 ·
-
bug :bug:
Dificultad 1/5 Menos de una hora Aptitud para principiantes 68/100
CommunityToolkit/dotnet#648 ·
-
bug :bug:
Dificultad 3/5 1-2 días Aptitud para principiantes 68/100
CommunityToolkit/dotnet#1215 ·
-
feature request :mailbox_with_mail:
Dificultad 5/5 Más de una semana Aptitud para principiantes 45/100
CommunityToolkit/dotnet#1214 ·
Todos los issues de CommunityToolkit/dotnet
Issues similares
-
bug P3
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
nightscout/nocturne#1908 ·
Los mantenedores suelen responder en 1 día
-
bug documentation Needs: Triage :mag:
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
WPF: each page's `Title` overwrites the window title, and returning to a page does not restore itAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 1 día
-
agentic-workflows area/Docs partner/agentic-workflows
Dificultad 1/5 Menos de una hora Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
jamesmontemagno/tiny-clips#378 · 2 comentarios ·
Los mantenedores suelen responder en 1 día