Visitar URL original
Avoid extra SMB queries when formatting file names by daxian-dbw · Pull Request #28038 · PowerShell/PowerShell · GitHub
Skip to content

Avoid extra SMB queries when formatting file names - #28038

Open
Dongbo Wang (daxian-dbw) wants to merge 1 commit into
PowerShell:masterfrom
daxian-dbw:daxian-dbw-investigate-network-dir-formatting
Open

Dongbo Wang (daxian-dbw) wants to merge 1 commit into
PowerShell:masterfrom
daxian-dbw:daxian-dbw-investigate-network-dir-formatting

Conversation

@daxian-dbw

@daxian-dbw Dongbo Wang (daxian-dbw) commented Sep 21, 2026 •

Copy link
Copy Markdown
Member

PR Summary

  • Check cached file attributes before inspecting detailed reparse-point metadata in NameString.
  • Avoid one FindFirstFile query per ordinary item when formatting directory listings, which is particularly expensive on SMB shares.
  • Add a regression test proving that cached non-reparse metadata avoids reopening the path.

PR Context

Fixes #27088.

IsReparsePointLikeSymlink must inspect the reparse tag to distinguish symbolic links and junctions from cloud-drive placeholders. Default formatting previously invoked that expensive check for every item, including ordinary non-links. NameString now uses the already-populated Attributes metadata to short-circuit ordinary items while preserving detailed classification for actual reparse points.

Benchmark

Measured 4,897 entries over the local UNC path \\localhost\c$\Windows\System32. Each result is the median of three warmed-up runs.

Measurement PowerShell 7.6.6 without fix Fixed debug build Improvement
NameString 3,870 ms 81 ms 48x faster
Default formatting 4,250 ms 727 ms 5.8x faster

A same-binary control using the fixed debug build isolates the avoided operation:

Operation Median
Guarded NameString 81 ms
Direct unconditional IsReparsePointLikeSymlink probe 3,939 ms

This confirms that the approximately 3.9-second cost came from calling FindFirstFile once per item. Absolute formatting times vary between release and debug builds, but the per-item SMB query is eliminated.

PR Checklist

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@daxian-dbw
Dongbo Wang (daxian-dbw) requested a review from a team as a code owner September 21, 2026 20:58
Copilot AI lite review requested due to automatic review settings September 21, 2026 20:58
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@daxian-dbw Dongbo Wang (daxian-dbw) added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Sep 21, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

No unresolved review issues were identified, and regression coverage was added.

Review effort: Lite
Findings: None

What changed in this PR

Improves file-name formatting performance by avoiding unnecessary SMB metadata queries for ordinary items.

Changes:

  • Uses cached attributes to short-circuit reparse-point inspection.
  • Adds regression coverage for cached metadata behavior.
File Description
test/​powershell/​Modules/​Microsoft.PowerShell.Management/​Get-Item.Tests.ps1 Verifies cached non-reparse items do not reopen their paths.
src/​System.Management.Automation/​namespaces/​FileSystemProvider.cs Avoids unnecessary metadata queries during formatting.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@microsoft-github-policy-service microsoft-github-policy-service Bot added the Review - Needed The PR is being reviewed label Sep 29, 2026
@microsoft-github-policy-service

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log Review - Needed The PR is being reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PS 7.6 - extremly slow output of dir on network drive

2 participants