AbsolutePath.ReadKind allocates a new 16 KiB buffer per directory on Windows: the pooled buffer is not returned on failure
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 78/100
Línea de trabajo
Empieza por TruePath/DiskUtils.cs, especialmente por TryGetReparseDataBuffer en torno a la obtención de un búfer mediante ArrayPool<byte>.Shared y la devolución cuando falla DeviceIoControl; después, sigue cómo AbsolutePath.ReadKind() lo llama en Windows. Reproduce la asignación reportada con el bucle proporcionado y revisa las pruebas existentes para los tipos de ruta de Windows. El trabajo estará listo cuando los directorios normales reutilicen el búfer obtenido o eviten obtenerlo y disminuya la asignación sin cambiar los resultados para los reparse points.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
AbsolutePath.ReadKind() on Windows ends up in DiskUtils.TryGetReparseDataBuffer for every directory. The method rents a 16 KiB buffer from ArrayPool<byte>.Shared, but returns it only on the success path. For anything that isn't a reparse point (i.e. almost every directory), DeviceIoControl(FSCTL_GET_REPARSE_POINT) fails, the method does an early return null, and the rented buffer is dropped. Every call then allocates a fresh 16 KiB array instead of reusing the pooled one.
Measured on ReadKind() (allocated bytes per call):
- a file: 41 B
- a directory: 16,480 B
Repro:
var dir = new AbsolutePath(Path.GetTempPath());
for (int i = 0; i < 100; i++) dir.ReadKind(); // warmup
var before = GC.GetAllocatedBytesForCurrentThread();
for (int i = 0; i < 10_000; i++) dir.ReadKind();
Console.WriteLine((GC.GetAllocatedBytesForCurrentThread() - before) / 10_000); // ~16480
This is not a correctness failure, but it defeats the pool and produces a lot of garbage in directory-walking code.
Recommendations
- Return the buffer on the
DeviceIoControlfailure path too.DeviceIoControlhas finished writing by then, so this is safe (the "abandon rather than return" advice only applies to buffers that might still be in use). - Alternatively, rent the buffer only when it is actually needed:
ReadKind()already reads the attributes, and a junction always hasFileAttributes.ReparsePointset, so the reparse query can be skipped for everything else. (A 16 KiBstackallocis not a good replacement for the pool: it is well above the ~1 KB guideline for stack buffers.)
- Lenguaje dominante
- C#
- Estrellas
- 107
- Forks
- 22
- Merge medio
- 3 d 2 h
- PR fusionados (30 d)
- 13
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin 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 ForNeVeR/TruePath
-
Wrong values of Kernel32.FileShare.Delete and Kernel32.FileAttributes.PosixSemanticsPosiblemente ocupada @ElectLive la tomó hace 2 días. Abiertobug good first issue help wanted
Dificultad 1/5 Menos de una hora Aptitud para principiantes 83/100
ForNeVeR/TruePath#241 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
enhancement good first issue help wanted
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
ForNeVeR/TruePath#165 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
Windows tests: symlink access requires dev mode or elevated accessPosiblemente ocupada @hamdiakin la tomó hace 1 día. Abiertodocumentation help wanted
Dificultad 3/5 1-2 días Aptitud para principiantes 57/100
ForNeVeR/TruePath#245 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
bug good first issue help wanted
Dificultad 3/5 Medio día Aptitud para principiantes 57/100
Los mantenedores suelen responder en 1 día
-
enhancement help wanted
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
Los mantenedores suelen responder en 1 día
Todos los issues de ForNeVeR/TruePath
Issues similares
-
needs-triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
elsa-workflows/elsa-foundation#3130 ·
Los mantenedores suelen responder en 1 día
-
遥测历史查询始终返回 HTTP 400,页面静默无结果Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
Format request: .wbpzAbiertoenhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
KnifeLemon/Filee#294 ·
Los mantenedores suelen responder en 1 día
-
good first issue
Dificultad 1/5 1-3 horas Aptitud para principiantes 88/100
GlebKievsky/git-tips#4 ·
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 77/100
OrchardCMS/OrchardCore#20088 · 1 comentario ·
Los mantenedores suelen responder en 1 día