🩹 [Patch]: Module startup is faster and performance checks are reproducible#69
🩹 [Patch]: Module startup is faster and performance checks are reproducible#69Marius Storhaug (MariusStorhaug) wants to merge 12 commits into
Conversation
Initialize Sodium once during module import and derive byte-array public keys directly. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Exercise concurrent runspace and process imports plus direct byte-array key derivation. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Super-linter summary
All files and directories linted successfully For more information, see the GitHub Actions workflow run Powered by Super-linter |
There was a problem hiding this comment.
Pull request overview
This PR improves the steady-state performance of Sodium’s PowerShell cryptographic commands by removing repeated per-command initialization overhead and reducing avoidable command-layer conversions, while keeping existing command parameters and return formats intact for current callers.
Changes:
- Removes redundant per-command
Initialize-Sodiumcalls from keygen, public-key derivation, encryption, and decryption command wrappers (relying on module import-time initialization instead). - Adds a managed
DerivePublicKey(string privateKeyBase64) -> byte[]API and updatesGet-SodiumPublicKey -AsByteArrayto return the derived byte array directly. - Expands Pester coverage for byte-array public-key derivation and parallel module load/crypto round-trips (runspaces + processes).
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/Sodium.Tests.ps1 | Adds coverage for byte-array public-key derivation and parallel module loading/round-trips. |
| src/functions/public/New-SodiumKeyPair.ps1 | Removes per-command initialization to reduce overhead. |
| src/functions/public/Get-SodiumPublicKey.ps1 | Returns a managed byte[] directly for -AsByteArray and keeps Base64 output path intact. |
| src/functions/public/ConvertTo-SodiumSealedBox.ps1 | Removes per-command initialization to reduce overhead. |
| src/functions/public/ConvertFrom-SodiumSealedBox.ps1 | Removes per-command initialization to reduce overhead. |
| PSModule/Sodium/Sodium.cs | Introduces DerivePublicKey returning byte[] and re-implements Base64 derivation via the new method. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Exercise idempotent initialization, buffer-size caching, unsupported platforms, and missing runtime diagnostics. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
tests/Sodium.Tests.ps1:171
Get-SodiumPublicKey -AsByteArrayreturns abyte[], but this assertion checks for a singlebyte. This will fail and also contradicts the subsequent[Convert]::ToBase64String($derivedPublicKey)call which requires abyte[].
It 'Get-SodiumPublicKey - Returns the public key as a byte array' {
$keyPair = New-SodiumKeyPair
$derivedPublicKey = Get-SodiumPublicKey -PrivateKey $keyPair.PrivateKey -AsByteArray
$derivedPublicKey | Should -BeOfType ([byte])
[Convert]::ToBase64String($derivedPublicKey) | Should -Be $keyPair.PublicKey
Isolate untriggerable native-load diagnostics, simulate the Windows registry branch, and assert byte-array output without pipeline enumeration. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Extract runtime identifier resolution for deterministic cross-platform tests and preserve byte arrays as single pipeline objects. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Shadow the platform flag so the cross-platform test executes the mocked registry lookup. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Use System.IO.Path::Combine for assembly path resolution and cache fixed Sodium key/seal/seed byte sizes without extra native calls during import. On this machine, cold import dropped from ~71.1 ms baseline to ~54.5 ms in repeated runs (~23% faster), with all tests still passing. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Module startup is now faster and performance regressions are easier to catch because the import path was optimized and repeatable benchmark tooling is included in the repository.
Changed: Faster module startup
Cold module import is significantly faster in fresh PowerShell sessions, and parallel session startup is also reduced, so common CLI and automation entry points spend less time on initialization.
pwsh)Changed: Reproducible performance verification
The repository now includes benchmark scripts for cold import timing, per-operation stopwatch measurements, and Profiler traces, so performance changes can be validated the same way in future PRs.
Technical Details
Import-Moduleassembly-load approach after evaluating alternatives becauseAdd-Type -PathandAssembly.LoadFromwere slower on measured runs.crypto_boxsize constants.tools/benchmarkscripts for local module assembly, stopwatch benchmarks, import benchmarks, and profiler traces, then cleaned them to satisfy linter rules.Related issues