Cache plugin step arrays and skip unused filter keys in the runtime#2915
Open
nohwnd wants to merge 1 commit into
Open
Cache plugin step arrays and skip unused filter keys in the runtime#2915nohwnd wants to merge 1 commit into
nohwnd wants to merge 1 commit into
Conversation
Invoke-TestItem and Invoke-Block rebuilt the framework plugin step arrays from $state.Plugin via member enumeration for every test and block, and reversed the teardown copies each time. The plugin set cannot change during a run (the only assignment is in Invoke-Test), so the arrays are now precomputed once into $state.PluginSteps, with the teardown arrays stored already reversed. Test-ShouldRun built the path:line key and the dotted path for every discovered item, but they are only read by the Line/ExcludeLine/FullName filters and by debug messages. They are now computed only when one of those consumers is present. New-Test rebuilt the test path from the runtime stack on every call, the parent block already holds the same reversed path, so reuse it. 🤖
This was referenced Jul 19, 2026
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.
Three changes on the per-test path in
Pester.Runtime.ps1:Invoke-TestItemandInvoke-Blockrebuilt the framework plugin step arrays from$state.Pluginvia member enumeration for every test and block, and reversed the teardown copies each time. The plugin set cannot change during a run (the only assignment to$state.Pluginis inInvoke-Test, and all plugin objects are fully built before that), so the arrays are now precomputed once into$state.PluginSteps, with the teardown arrays stored already reversed.Invoke-ScriptBlocknever mutates the arrays it receives, it filters them into fresh locals, so sharing one instance across all tests is safe.Test-ShouldRunbuilt thepath:linekey (string interpolation plus a regex-replace) and the dotted path (-join) for every discovered item, but they are only read by theLine/ExcludeLine/FullNamefilters and by debug messages. They are now computed only when one of those consumers is present, in the common no-filter run they are skipped entirely.New-Testrebuilt the test path from the runtime stack (ToArrayplusReverse) on every call. The parent block already holds the same reversed path, so reuse it.The plugin array caching alone is ~5-8us per test. A patched vs stock run produces identical output across
Normal/Detailed/Diagnosticverbosity, and the Diagnostic trace shows the executed step sequence is unchanged.Verification: full suite green on macOS (inline and dot-sourced build),
Pester.Runtime.ts.ps1(101 tests, drives the runtime directly including the plugin step ordering) andPester.Rspec.Filtering.ts.ps1pass in fresh processes.Related perf PRs: #2914, #2916, #2917, #2918. Measured together they cut ~21% from four representative workloads (inline build, macOS).
🤖