Skip to content

PSScriptAnalyzer linting takes ~35 minutes in WSL2 due to recursive file discovery and PATH scanning #674

@WilliamBerryiii

Description

@WilliamBerryiii

Description

npm run lint:ps takes approximately 35 minutes to complete in WSL2 environments, making local development iteration impractical. The expected runtime for 52 PowerShell files is under 1 minute.

Root Causes

1. Recursive file discovery via Get-ChildItem

Get-FilesRecursive in LintingHelpers.psm1 uses Get-ChildItem -Recurse to find PowerShell files. This traverses the entire filesystem tree (12,040+ items including node_modules/, .git/, and other irrelevant directories) to locate 52 PowerShell files. The gitignore filtering happens after enumeration, so the full traversal cost is always paid.

2. WSL2 PATH containing Windows mount points

WSL2 environments typically have 30+ /mnt/* entries in $env:PATH (Windows system directories shared via Plan 9/9P protocol over Hyper-V AF_VSOCK sockets). PSScriptAnalyzer/.NET resolves commands by scanning every PATH directory for each file analyzed. Each /mnt/* lookup triggers a cross-filesystem openat syscall through the 9P protocol, adding ~0.5-1 second per file analyzed.

Combined, these cause ~5,600 slow cross-filesystem syscalls per linting run, confirmed via strace.

Fix

PR #667 addresses both root causes:

  • Get-FilesRecursive: Uses git ls-files --cached --others --exclude-standard (scoped to the $Path parameter) with fallback to Get-ChildItem -Recurse for non-git contexts
  • Invoke-PSScriptAnalyzer.ps1: Strips /mnt/* entries from PATH before running analysis (guarded by the direct-invocation check so it does not affect dot-sourced test imports)

Validation

After fix: 52 files analyzed, 0 issues, ~40 seconds (down from ~35 minutes).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingperformancePerformance improvement

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions