Skip to content

Performance problem: -Name slows down Get-ChildItem -Recurse #9119

@mklement0

Description

@mklement0

-Name is a convenient switch to only output item names (without -Recurse) or relative paths (with -Recurse).

Given that only string instances rather than System.IO.File/DirectoryInfo instances are output, one would expect -Name to speed things up (or at least not to slow things down); however, with -Recurse present, -Name slows down the command noticeably.

Steps to reproduce (on Windows)

# Warm up the cache
$null = Get-ChildItem -Recurse 'C:\Program Files' 

# Without -Name
(Measure-Command { Get-ChildItem -Recurse 'C:\Program Files' }).TotalSeconds

# With -Name
(Measure-Command { Get-ChildItem -Name -Recurse 'C:\Program Files' }).TotalSeconds

Expected behavior

The command with -Name should be faster (or at least not slower).

Actual behavior

Sample timings:

1.544098   # without -Name
4.5759553  # with -Name

That is, adding -Name made the command about 3 times slower.

Environment data

PowerShell Core 6.2.0-preview.4

Metadata

Metadata

Assignees

Labels

Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-No ActivityIssue has had no activity for 6 months or moreUp-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Cmdlets-Managementcmdlets in the Microsoft.PowerShell.Management moduleWG-Engine-Performancecore PowerShell engine, interpreter, and runtime performance

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions