Repository navigation
Index brace and pipeline lookups during formatting - #2224
Open
Przemysław Kłys (PrzemyslawKlys) wants to merge 1 commit into
Open
Przemysław Kłys (PrzemyslawKlys) wants to merge 1 commit into
Przemysław Kłys (PrzemyslawKlys) wants to merge 1 commit into
Conversation
Przemysław Kłys (PrzemyslawKlys)
requested review from
a team and
Christoph Bergmeister (bergmeister)
as code owners
October 8, 2026 10:52
Copilot started reviewing on behalf of
Przemysław Kłys (PrzemyslawKlys)
October 8, 2026 10:52
View session
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The optimizations preserve prior selection semantics and are supported by focused tests.
0 open findings
What changed in this PR
Optimizes formatter token and pipeline lookups while preserving existing output and ordering.
Changes:
- Indexes brace tokens by offset.
- Indexes pipeline endings by line.
- Adds brace-selection and AST-order coverage.
| File | Description |
|---|---|
Engine/TokenOperations.cs |
Adds offset-based brace lookup. |
Rules/UseConsistentIndentation.cs |
Adds line-indexed pipeline-end lookup. |
Tests/Engine/TokenOperations.tests.ps1 |
Tests brace filtering and ordering. |
🧠 Review effort: Balanced
Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.
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
Formatting large merged modules repeatedly scans the token array for script-block braces and scans earlier pipelines for each token. Index brace tokens by offset and pipeline endings by line, preserving the existing first-match selection and AST order. This changes no public API or formatting output.
On PowerForge-merged repository functions from Locksmith and PSWriteHTML, the formatted PSM1 and original manifest bytes match unchanged upstream (
411c3d0) exactly. Mean warmedInvoke-Formattertime over three rotated samples:0xFFFF0xFFFF0xFFFF00000xFFFF0000These are local PowerShell 7.6.6 measurements on a Ryzen 9 9950X3D2. Comparisons are pinned to one L3 domain at a time: three rotated samples on
0xFFFF, two on0xFFFF0000, retaining every sample. Each sample uses a fresh process; startup/import are excluded, and four workload passes are discarded before the warm measurement. Two small PSWriteHTML function files take about 10 ms together with either version. First-call timings do not show a consistent improvement. The merged workloads exclude optional dependency inlining and module execution and use the same six formatting rules. This optimization is independent of #2206's command-discovery changes.Release builds passed for
net8andnet462. The TokenOperations, InvokeFormatter, UseConsistentIndentation, PlaceOpenBrace and PlaceCloseBrace suites passed: 157 tests on PowerShell 7; 155 tests and two platform skips on Windows PowerShell 5.1. The new test checks brace selection and nested AST ordering.PR Checklist