Skip to content

test: import the module once per run - #40

Merged
fadwen merged 1 commit into
mainfrom
perf/suite-startup
Sep 14, 2026
Merged

fadwen merged 1 commit into
mainfrom
perf/suite-startup

Conversation

@fadwen

@fadwen fadwen commented Sep 14, 2026

Copy link
Copy Markdown
Owner

Item 7 from the optimisation list, the last one.

What was measured

Import Cost
Import-Module -Force, cold 810 ms
Import-Module -Force, warm 190 ms
Import-Module when already loaded 9 ms

Every one of the 111 test files forced a warm import in BeforeAll and removed the module in AfterAll: about 21 seconds of an 80-second run.

What changed

Each file now imports the module only if it is not already loaded, and none removes it afterwards. Module.Contract.Tests.ps1 keeps its forced import, because it asserts what a freshly imported module looks like, including that no provider is active.

The trade

State one file leaves in the module is now visible to the next. Fourteen suites write a provider connection into module scope, and several connect through the real command. That is exactly the kind of dependency the shuffled CI run from #35 exists to catch: a test that only passes after a fresh import, or only before another file connected, fails there with a seed to replay. Three shuffled seeds locally and the CI runs on this PR all pass, so no such dependency exists today, and the shuffle is what keeps it that way.

Verification

Check Result
PowerShell 7, shuffled, seeds 7, 20260914, 99991 2,498 passed each, 74, 68 and 57 seconds
Windows PowerShell 5.1, shuffled 2,499 passed, 133 seconds, down from about 150
ScriptAnalyzer 0 findings

Every one of the 111 test files forced a fresh import in its BeforeAll and
removed the module in its AfterAll, at about 190 ms each: a quarter of the
run on a workstation. A file now imports the module only if it is not loaded
and leaves it loaded. State one file leaves behind is visible to the next,
which the shuffled CI run catches with a seed to replay; the contract suite
still forces a fresh import, because it asserts what a freshly imported
module looks like.

Measured: 80 seconds to about 65 on PowerShell 7 across three shuffled seeds,
150 to 133 on Windows PowerShell 5.1.
@fadwen
fadwen merged commit bf383da into main Sep 14, 2026
4 checks passed
@fadwen
fadwen deleted the perf/suite-startup branch September 14, 2026 03:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant