Skip to content

Return the pooled reparse buffer on every path in TryGetReparseDataBuffer (#240) - #246

Merged
ForNeVeR merged 5 commits into
ForNeVeR:mainfrom
FalconTechDev:fix-240-reparse-buffer
Oct 24, 2026
Merged

ForNeVeR merged 5 commits into
ForNeVeR:mainfrom
FalconTechDev:fix-240-reparse-buffer

Conversation

@FalconTechDev

@FalconTechDev FalconTechDev commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Closes #240

TryGetReparseDataBuffer rents a 16 KiB buffer from ArrayPool<byte>.Shared but only returned it when DeviceIoControl succeeded. For almost every directory the call fails because it is not a reparse point, the method returned early, and the buffer was dropped. So every ReadKind() on a directory allocated a new 16 KiB array.

The rent is now inside a try/finally so the buffer always goes back to the pool. DeviceIoControl has finished writing by then, so reusing it is safe.

I added a test, Windows only, that calls ReadKind() on a directory and checks it allocates less than 1 KiB per call. Without the fix it fails with 16,576 bytes per call. With the fix it passes, and the whole TruePath.Tests run on net8.0 is 471 passed, 0 failed on Windows 11. To run it locally I had to bump global.json to the SDK I have installed; that change is not in the PR. There is also a changelog entry under Unreleased.

I did not do the other idea from the issue (skip the reparse query when the ReparsePoint attribute is not set). I can do it as a follow up if you prefer that.

@ForNeVeR
ForNeVeR self-requested a review October 19, 2026 11:03
@ForNeVeR ForNeVeR self-assigned this Oct 19, 2026
@ForNeVeR
ForNeVeR force-pushed the fix-240-reparse-buffer branch from b40df4d to 8ae7e34 Compare October 24, 2026 20:56
@ForNeVeR
ForNeVeR force-pushed the fix-240-reparse-buffer branch 2 times, most recently from 6432d3e to 75b2ffa Compare October 24, 2026 21:45
@ForNeVeR
ForNeVeR force-pushed the fix-240-reparse-buffer branch from 75b2ffa to e33aeab Compare October 24, 2026 21:51

@ForNeVeR ForNeVeR left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I did some more digging and managed to reduce the allocations even more, but I'll mention your contribution in the release notes.

@ForNeVeR
ForNeVeR merged commit dc2a40b into ForNeVeR:main Oct 24, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AbsolutePath.ReadKind allocates a new 16 KiB buffer per directory on Windows: the pooled buffer is not returned on failure

2 participants