AbsolutePath.ReadKind allocates a new 16 KiB buffer per directory on Windows: the pooled buffer is not returned on failure
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 78/100
Hướng nghiên cứu
Bắt đầu với TruePath/DiskUtils.cs, đặc biệt là TryGetReparseDataBuffer quanh việc thuê bộ đệm qua ArrayPool<byte>.Shared và trả lại khi DeviceIoControl thất bại; sau đó lần theo cách AbsolutePath.ReadKind() gọi nó trên Windows. Tái hiện mức cấp phát được báo cáo bằng vòng lặp đã cung cấp và kiểm tra các bài kiểm thử hiện có cho các loại đường dẫn Windows. Công việc hoàn tất khi các thư mục thông thường tái sử dụng bộ đệm đã thuê hoặc tránh thuê bộ đệm, đồng thời mức cấp phát giảm mà không làm thay đổi kết quả đối với reparse point.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.)
- Ngôn ngữ chính
- C#
- Star
- 107
- Fork
- 22
- Merge trung bình
- 3 ngày 2 giờ
- Pull request đã merge (30 ngày)
- 13
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của ForNeVeR/TruePath
-
Wrong values of Kernel32.FileShare.Delete and Kernel32.FileAttributes.PosixSemanticsCó thể đã có người làm @ElectLive đã nhận hôm nay. Đang mởbug good first issue help wanted
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 83/100
ForNeVeR/TruePath#241 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement good first issue help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
ForNeVeR/TruePath#165 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
documentation help wanted
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 57/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug good first issue help wanted
Độ khó 3/5 Nửa ngày Mức phù hợp với người mới 57/100
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement help wanted
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của ForNeVeR/TruePath
Issue tương tự
-
Backend enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 1 ngày
-
UI: money shows the minus sign next to the number, not before the currency (IL -3.0m, not -IL 3.0m)Đang mởarea: sim area: unity enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
eyalgolan/statecraft-israel#1107 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
dimitar-radenkov/Pointframe#271 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
qew21/Genshin-Subtitles#45 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
HoffmanEngineering/3d-print-log-api#274 ·
Maintainer thường phản hồi trong vòng 1 ngày