Repository navigation
perf(core): read protected path forms from their cache per entry - #1989
Merged
Merged
Conversation
Test-SafePath runs once for every entry of every tree a cleanup walks, and Test-MoleProtectedPathForm called Get-MoleProtectedPathForms once per protected entry for each of them: the UWP Packages root (after a Join-Path), the profile root and each of the ten protected system paths. Every call was a cache hit, but a Windows PowerShell 5.1 function call costs more than the comparisons it feeds, so the check spent about 1 ms per entry on calls alone. The dry run of a Bun package cache with about 87,000 entries drops from 283 s to 175 s. Read the forms straight from the cache and call the builder only on a miss. The Packages root is kept per LOCALAPPDATA value, so Join-Path runs once per value. The lists, the cached forms and the comparisons are unchanged; a changed LOCALAPPDATA or a protected entry added at runtime is a miss and is built as before. Tests cover both, and a mock counts the builder calls on a warm cache (12 before, 0 after).
Owner
|
@b84330808 Thanks for the careful measurements. Pester passed on both Windows PowerShell 5.1 and pwsh 7, so it's merged. Windows CLI installs follow the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
mo clean --dry-runsat on "Developer tools" for several minutes on my Windows 11 machine. Almost all of it was the Bun cache row (%USERPROFILE%\.bun\install\cache: 2,444 package folders, about 87k files and folders, 920 MB). Every entry of every walked tree goes throughTest-SafePath, and a big part of that check was PowerShell call overhead rather than the comparisons.Test-MoleProtectedPathFormcalledGet-MoleProtectedPathFormsonce per protected entry for every candidate: the UWPPackagesroot (after aJoin-Path), the profile root and each of the 10$script:ProtectedPaths. Every call was a cache hit, but a Windows PowerShell 5.1 function call costs more than the string comparisons it feeds.This change reads the forms straight from
$script:MoleProtectedPathFormCacheand callsGet-MoleProtectedPathFormsonly on a miss. ThePackagesroot is kept perLOCALAPPDATAvalue, soJoin-Pathruns once per value. The lists, the cached forms and the comparisons are unchanged. A changedLOCALAPPDATAor a protected entry added at runtime is a cache miss and is built as before.Numbers
Windows 11 Pro 25H2, Windows PowerShell 5.1, i7-9700, NVMe SSD, warm file cache. Base is
windowsat 6bf9772. Base and patched runs alternated.Test-SafePathper entry, the first 2,000 entries of the Bun cache, whitelist state passed in as the clean walks do, 6 runs each: 1.82-1.83 ms on base, 0.83-0.85 ms patched.Whole Bun cache row (
Clear-MoleAppCachewith dry run on), 2 runs each: 271.0 s and 269.2 s on base, 161.7 s and 162.7 s patched. All four printBun cache (2444 items, 921.7MB dry).Safety Review
Test-MoleProtectedPathFormreaches forms it already cached.Tests
./scripts/check.sh,./scripts/test.sh)Three new cases in
tests/Core.Tests.ps1: a mockedGet-MoleProtectedPathFormsis called 0 times on a warm cache (12 times on the base, so that case fails without the change), thePackagesrule follows aLOCALAPPDATAchange, and a protected entry added after earlier checks is honored.Pester 5.7.1 on Windows PowerShell 5.1 with the
base.ps1change, before the new cases were added: Protection, Core, Clean, CleanupBoundary, CleanupTargets, AppCacheSafety, DryRun, DryRunEnvironment, PreviewNoWrite and PurgeBoundary, 433 passed and 1 failed. The failure isClean leaves user data alone.Lists the cache rows it keeps, which fails the same way on the unchanged base on this machine. Core.Tests alone with the new cases: 94 passed. I did not run the fullscripts\test.ps1or pwsh 7.Safety-related changes