Skip to content

Perf - #13

Merged
jessehouwing merged 16 commits into
mainfrom
perf
Sep 14, 2026
Merged

Perf#13
jessehouwing merged 16 commits into
mainfrom
perf

Conversation

@jessehouwing

Copy link
Copy Markdown
Owner

This pull request makes significant improvements to the CommandInfoCache and related command metadata handling in the ScriptAnalyzer engine. The main focus is on thread safety, improved caching, and more robust handling of PowerShell command metadata, especially for parameter information. It introduces a new CommandParameterSnapshot class to safely cache detached parameter metadata, and it refactors how command and parameter information is retrieved and cached to avoid threading issues with the PowerShell engine.

Thread safety and runspace management:

  • Refactored CommandInfoCache to use a single Runspace and a re-entrant lock (_runspaceLock) instead of a RunspacePool, ensuring all PowerShell engine access is serialized and thread-safe. This prevents transient failures due to PowerShell's lack of thread safety. [1] [2]
  • Updated disposal logic to ensure the runspace cannot be disposed while lookups are in flight, further improving thread safety.

Command and parameter metadata caching:

  • Added caching for parameter snapshots and mandatory parameter names using new concurrent dictionaries, reducing redundant metadata queries and improving performance. [1] [2]
  • Introduced the CommandParameterSnapshot class to safely store and retrieve parameter facts without needing to access PowerShell runspace objects, avoiding runspace affinity issues.

Improved error handling and cache eviction:

  • Enhanced error handling to distinguish between command resolution errors and other exceptions, ensuring failed lookups are not cached and can be retried. Faulted cache entries are now evicted to prevent persistent failures. [1] [2] [3]

Helper and analysis improvements:

  • Updated Helper.GetExportedFunction to use the new parameter snapshot mechanism for Export-ModuleMember, eliminating dynamic parameter resolution and improving reliability in multi-threaded analysis. [1] [2]
  • Added GetModuleManifestForAnalysis to share module manifest validation between rules during a single analysis, reducing redundant work.

Miscellaneous:

  • Fixed hash code calculation in CommandLookupKey to use StringComparer.OrdinalIgnoreCase for correctness.

These changes collectively make command and parameter metadata handling safer, faster, and more robust, especially under concurrent analysis scenarios.## PR Summary
when the PR is ready.

Copilot AI and others added 16 commits September 14, 2026 20:01
Co-authored-by: jessehouwing <4173387+jessehouwing@users.noreply.github.com>
Co-authored-by: jessehouwing <4173387+jessehouwing@users.noreply.github.com>
Co-authored-by: jessehouwing <4173387+jessehouwing@users.noreply.github.com>
Co-authored-by: jessehouwing <4173387+jessehouwing@users.noreply.github.com>
…cs-gathering

Disable benchmark metrics and consolidate performance comparisons
Co-authored-by: jessehouwing <4173387+jessehouwing@users.noreply.github.com>
Co-authored-by: jessehouwing <4173387+jessehouwing@users.noreply.github.com>
Co-authored-by: jessehouwing <4173387+jessehouwing@users.noreply.github.com>
Co-authored-by: jessehouwing <4173387+jessehouwing@users.noreply.github.com>
Make engine retries verifiable and centralize metadata recovery
Co-authored-by: jessehouwing <4173387+jessehouwing@users.noreply.github.com>
Expand perf workflow to benchmark `perf` with and without `DISABLE_ENGINE_RETRIES`
Co-authored-by: jessehouwing <4173387+jessehouwing@users.noreply.github.com>
…isons

Restore benchmark comparisons and explicit retry variants
- Drop retry loops and DISABLE_ENGINE_RETRIES flag from CommandInfoCache;
  failed lookups evict the cache entry and return null gracefully
- Delete PerformanceTelemetry and all metrics collection from the engine,
  benchmark harness, workflows and tests
- Refactor GetCommandMetadata to Func<CommandInfo, T>
- Add lookup-count and module-qualified resolution tests
- Rework Issue2205 repro into generic ParallelRuleExecution test with a
  bounded synthetic workload, no Linux filter

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Benchmark now compares upstream@main against fork@main only, in
preparation for merging the perf branch to main. Also makes source a
proper matrix dimension.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jessehouwing
jessehouwing merged commit 7d4a11f into main Sep 14, 2026
2 of 3 checks passed
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.

2 participants