⚡ Sangsakala Proxy 🏠 Home
Skip to content

Add experimental lazy metadata for FileSystem provider output - #28284

Open
Staffan Gustafsson (powercode) wants to merge 4 commits into
PowerShell:masterfrom
powercode:Perf/FileInfoPsProps
Open

Staffan Gustafsson (powercode) wants to merge 4 commits into
PowerShell:masterfrom
powercode:Perf/FileInfoPsProps

Conversation

@powercode

@powercode Staffan Gustafsson (powercode) commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

PR Summary

Add PSOptimizedProviderObjects, an experimental feature that avoids allocating provider note properties until they are needed.

FileSystem items and scalar Get-Content strings/bytes store metadata inline in PSObject<TMetadata>. Property reads use compiled getters; member inspection or mutation materializes ordinary PSNoteProperty objects. Content outputs share cached paths and keep their own ReadCount. Batches, byte arrays, and other providers use the existing path.

Enable-ExperimentalFeature PSOptimizedProviderObjects
# Restart PowerShell.

One behavior change: lazy FileSystem path properties follow the underlying object's current path after a move. Once materialized, they become snapshots. Drive/provider context, Unix stat, and content paths retain their captured values.

Performance

Measures of Get-ChildItem | ... for different scenarios with different usage of the PS* provider properties.

Elapsed time and allocated bytes per filesystem item relative to master

Master is 100% (dashed line); lower is better. Left: elapsed time. Right: allocated bytes per item.

  • Emission: 55.4% less time, 67.3% fewer allocated bytes.
  • One PSPath read per item: 52.3% less time, 58.2% fewer allocated bytes.
  • Ten reads: 51.6% less time, but 14.1% more allocated bytes, as path strings are recomputed.
  • Formatting and Select-Object * show little improvement.

Measured on an i9-13900K with fast disks. Your mileage may vary.

Tests and docs

Adds xUnit and Pester coverage for lazy reads, mutation, binding, copying, serialization, object lifetime, content metadata, and feature-on/off behavior. Includes a process-isolated benchmark harness and an engine design guide at docs/building/provider-instance-metadata.md.

image

PR Checklist

@azure-pipelines

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

@powercode Staffan Gustafsson (powercode) added WG-Engine core PowerShell engine, interpreter, and runtime CL-Engine Indicates that a PR should be marked as an engine change in the Change Log labels Oct 29, 2026
@microsoft-github-policy-service microsoft-github-policy-service Bot added the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Nov 2, 2026
@microsoft-github-policy-service microsoft-github-policy-service Bot removed the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Nov 2, 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.

🟡 Changes recommended

Unresolved wrapper-unwrapping regressions break .NET argument handling, property assignments, and Boolean binding, while an incorrect path causes the new filesystem test to fail on Unix.

7 open issues
What changed in this PR

Adds the opt-in PSOptimizedProviderObjects feature to reduce provider-output allocations by deferring note-property creation until member inspection or mutation requires it.

Changes:

  • Introduces inline metadata and lazy property access for FileSystem items and scalar Get-Content output.
  • Adds regression coverage, isolated performance benchmarks, and engine design documentation.
  • Updates debugger configuration, solution mappings, and small provider/console-host details.
File Description
TestDir/​test.ps1 Adds a local FileSystem test helper.
test/​xUnit/​csharp/​test_PSObject.cs Tests lazy access, promotion, identity, copying, serialization, and allocations.
test/​powershell/​Modules/​Microsoft.PowerShell.Management/​OptimizedProviderObjects.Tests.ps1 Adds feature-dependent provider and content integration tests.
test/​powershell/​Modules/​Microsoft.PowerShell.Management/​FileSystem.Tests.ps1 Updates Unix colon-path tests.
test/​perf/​benchmarks/​README.md Documents benchmark usage and measurement interpretation.
test/​perf/​benchmarks/​ProviderMetadata.ProcessBenchmark.ps1 Runs isolated baseline/candidate comparisons and generates reports.
test/​perf/​benchmarks/​assets/​ProviderMetadata.Measure.ps1 Measures item/content scenarios, allocations, and retained memory.
src/​System.Management.Automation/​System.Management.Automation.csproj Defaults UseResharper to false.
src/​System.Management.Automation/​Properties/​launchSettings.json Adds an executable debugger profile.
src/​System.Management.Automation/​namespaces/​RegistryProvider.cs Simplifies default-drive initialization.
src/​System.Management.Automation/​namespaces/​ProviderBase.cs Gates lazy FileSystem metadata attachment and preserves fallback handling.
src/​System.Management.Automation/​namespaces/​FileSystemProvider.cs Adds lexical metadata path helpers and shares path-fix logic.
src/​System.Management.Automation/​engine/​runtime/​Binding/​Binders.cs Separates instance-member presence checks from lazy value reads.
src/​System.Management.Automation/​engine/​ProviderPSObject.cs Implements typed metadata wrappers, compiled accessors, and FileSystem metadata.
src/​System.Management.Automation/​engine/​parser/​Compiler.cs Caches reflection references for new binder helpers.
src/​System.Management.Automation/​engine/​MshObject.cs Adds provider-source attachment and lookup helpers.
src/​System.Management.Automation/​engine/​MshMemberInfo.cs Supports lazy storage and promotion to ordinary note properties.
src/​System.Management.Automation/​engine/​InternalCommands.cs Keeps exact provider-property reads lazy in ForEach-Object.
src/​System.Management.Automation/​engine/​ExperimentalFeature/​ExperimentalFeature.cs Registers PSOptimizedProviderObjects.
src/​System.Management.Automation/​engine/​CommandParameter.cs Expands command-parameter debugger display.
src/​Microsoft.PowerShell.ConsoleHost/​host/​msh/​ConsoleHostRawUserInterface.cs Avoids redundant console-mode changes.
src/​Microsoft.PowerShell.Commands.Management/​commands/​management/​ContentOutputMetadata.cs Defines shared content-path accessors and per-output ReadCount.
src/​Microsoft.PowerShell.Commands.Management/​commands/​management/​ContentCommandBase.cs Emits optimized scalar content and centralizes path caching.
PowerShell.sln Maps Linux and CodeCoverage configurations to Release for affected projects.
docs/​building/​provider-instance-metadata.md Explains metadata design, lifecycle, compatibility, and validation.
docs/​building/​internals.md Summarizes the feature and links its design guide.
.vscode/​launch.json Adds console and WSL debugger configurations.

Review effort: Balanced

Comment thread .vscode/launch.json Resolved
Comment thread .vscode/launch.json Resolved
Comment thread TestDir/test.ps1 Resolved
Use inline ReadCount and shared source context for filesystem string and scalar-byte output. Preserve legacy metadata for raw byte arrays and batches. Include regression coverage, isolated benchmarks, and engine design documentation.
@powercode

Copy link
Copy Markdown
Collaborator Author

The 4 failing checks seem to be infrastructure issues.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-Engine Indicates that a PR should be marked as an engine change in the Change Log WG-Engine core PowerShell engine, interpreter, and runtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants