| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
The analysis cache is written by a background task that waits at least 13 seconds after the last change. A pwsh process that runs one command and exits sooner, such as pwsh -Command or -File, never saves it, so every such process analyzes the same modules again when a command is auto-loaded. If a save is still pending when the process exits, write the cache from a ProcessExit handler. A lock keeps the exit handler and the delayed write from running at the same time. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Sorry, something went wrong.
There was a problem hiding this comment.
Temporary cache snapshots register ProcessExit handlers that retain their entire Entries dictionaries until shutdown, allowing repeated merges to accumulate memory in long-running hosts.
1 open issue What changed in this PRAddresses #28375 by saving pending module analysis cache updates when PowerShell exits, avoiding repeated module analysis in short-lived processes.
Changes:
| File | Description |
|---|---|
| test/powershell/engine/Module/ModuleAnalysisCache.Tests.ps1 | Tests cache persistence after a short-lived process exits. |
| src/System.Management.Automation/engine/Modules/AnalysisCache.cs | Adds exit-time saving and synchronization with delayed writes. |
Review effort: Balanced
Sorry, something went wrong.
Serialize reads another process's cache into a temporary AnalysisCacheData to merge it, and that instance can queue a save from its delayed Cleanup. The ProcessExit handler captured the instance, so each such temporary instance stayed alive until the process exited. Register one static handler that only saves the process-wide cache. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
| Back | FazBrowse Home | New Git URL |
PR Summary
Fixes #28375.
The module analysis cache is written by a background task that waits at least 13 seconds after the last change, so a pwsh that runs one command and exits sooner (pwsh -Command, pwsh -File) never saves it, and every such process analyzes the same modules again when a command is auto-loaded.
When QueueSerialization queues the first save, it now also registers a ProcessExit handler that writes the cache if the save is still pending. A lock keeps the handler and the delayed write from running at the same time. The delayed write is unchanged for long-running sessions. Once the cache is up to date nothing is queued, so later processes do not write it again.
PR Context
Measured on Windows 11 26100 (i9-10900K), Release builds of master 1aac7f5 with and without this change (the two differ only in System.Management.Automation.dll), default cache location, 40 interleaved runs, median of paired differences with 95% confidence interval:
The first run writes the cache (4 KB here); later runs did not rewrite it.
Tests: added test/powershell/engine/Module/ModuleAnalysisCache.Tests.ps1, which starts pwsh with PSModuleAnalysisCachePath in TestDrive, auto-loads Get-ChildItem and checks that the cache file exists after the process exits. It fails without the change and passes with it. CommandDiscovery, Import-Module, ModulePath, Base-Directory and TabCompletion tests give the same results with and without the change on my machine.
I used GitHub Copilot to investigate this and to help write the change and test; I reviewed the code and ran the tests above myself.
PR Checklist