Repository navigation
Reduce per-entry overhead in Expand-Archive - #169
Merged
Steve Lee (SteveL-MSFT) merged 2 commits intoNov 20, 2026
Merged
Steve Lee (SteveL-MSFT) merged 2 commits into
Steve Lee (SteveL-MSFT) merged 2 commits into
Conversation
Expand-Archive spends most of its time on script work per entry rather than on extracting. For each entry it runs New-Object for a generic List in Get-WindowsArchiveEntryPathValidationResult and for a FileInfo, calls Test-Path -PathType Container on the parent folder and trims the path segments with a ForEach-Object pipeline. Collect the updated segments with a foreach statement, cast the path to FileInfo, check the parent folder with [System.IO.Directory]::Exists and trim the segments with a foreach statement. These all work on PowerShell 3.0, which the manifest still declares. Add tests that expand an archive with nested folders, empty folder entries, a zero-byte file, binary content and Unicode names, and check the extracted files byte for byte and the exact -PassThru output, both for a fresh expansion and for -Force over an existing one. Also cover a reserved device name in a nested entry. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Steve Lee (SteveL-MSFT)
requested changes
Nov 20, 2026
Review feedback. Keep the segments in a List[string] created with ::new() instead of collecting the foreach output into a string array. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Steve Lee (SteveL-MSFT)
merged commit Nov 20, 2026
448033d
into
PowerShell:servicing
5 checks passed
Alexandre Zollinger Chohfi (azchohfi)
deleted the
expand-archive-per-entry-perf
branch
November 20, 2026 23:01
5 tasks done
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.
PR Summary
Expand-Archive does some script work for every entry before it extracts it, and with many small files that work takes most of the time. This change makes it cheaper without changing what gets extracted or what
-PassThrureturns.For each entry the loop used to
List[string]withNew-ObjectinGet-WindowsArchiveEntryPathValidationResult(Windows only).New-Objectwith a generic type name searches the loaded assemblies on every call.FileInfowithNew-ObjectTest-Path -PathType Containeron the parent folder. The FileSystem provider fixes the casing of the whole path on every call, which costs a few milliseconds per call for a nested folder on Linux.ForEach-ObjectpipelineNow it collects the segments with a
foreachstatement, casts the path toFileInfo, checks the parent folder with[System.IO.Directory]::Exists()and trims the segments with aforeachstatement. The manifest still saysPowerShellVersion="3.0", so I avoided::new().This addresses PowerShell/PowerShell#28471.
PR Context
Expand-Archive of a zip with 2,000 small files in 200 folders on Windows 11, time inside the command, patched module over the servicing module, both loaded from unsigned copies in the same pwsh. Two separate runs of paired passes, median ratio with a 95% interval.
That's about 2.8 s less per expansion. Those runs used an earlier version of this change written with
::new(). I ran this branch once more against servicing, 10 paired passes with the earlier version in the same run. On Windows this branch came out at 0.62x [0.53, 0.70], about 3.1 s less, and the earlier version at 0.60x. On Linux (WSL2, ext4) the same run gave 0.23x [0.22, 0.27], about 9.6 s less on a 13 s expansion, becauseTest-Pathis most of the per-entry cost there. Linux was only measured in that one run.The extracted files are byte-identical and
-PassThrureturns the same items in the same order, on both platforms.The new tests expand an archive with nested folders, empty folder entries, a zero-byte file, binary content and Unicode names (Cyrillic, CJK, Greek and an emoji). They compare every file byte for byte and the exact
-PassThruoutput, for a fresh expansion and for-Forceover an existing one with a changed file and a deleted folder. There's also a test for a reserved device name in a nested entry, since the segment handling changed. They pass with and without this change, so they pin the current behaviour.PowerShell 7.6.10 and 7.7.0 ship 1.2.7, which isn't on this branch yet (PowerShell/PowerShell#28410). Its Expand-Archive makes the same calls per entry and also checks a growing array with
-notcontains. I can redo this on top of 1.2.7 once it's published.I used GitHub Copilot to investigate this and to help write the change and tests. I reviewed the code and ran the tests myself.
PR Checklist