Skip to content

perf: stop scanning unrelated DLLs for built-in analyzer rules - #1

Open
darrenator[bot] wants to merge 1 commit into
immybot-latestfrom
ao/immybot-279/analyzer-discovery
Open

darrenator[bot] wants to merge 1 commit into
immybot-latestfrom
ao/immybot-279/analyzer-discovery

Conversation

@darrenator

@darrenator darrenator Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Release Notes

None. ImmyBot package integration is separate.

Internal Release Notes

PowerShell Core rule discovery loads the known analyzer assemblies instead of every adjacent DLL. Unrelated host assemblies and their missing dependencies no longer interfere with built-in discovery. Explicit PowerShell custom rules remain supported.

Motivation

After merging immense/immybot#11257, Darren asked whether the repeated PSScriptAnalyzer DLL scans could be restricted and requested a fix with before/after measurements. That PR exposed the engine scanning roughly 410 application DLLs four times per analysis; an EF design assembly with an unavailable dependency caused diagnostics to disappear.

The fork hard-codes *.dll for Core discovery. IncludeRule/ExcludeRule filter rule names after discovery, so they cannot prevent these loads. Built-ins already live in known assemblies; loading those directly removes the unnecessary scan without requiring a new setting or glob API.

Summary

 initialize analyzer
-  enumerate/load every adjacent DLL for each of four interfaces
+  discover loggers in the engine assembly
+  discover script/token/DSC rules in BuiltinRules
   create fresh rule instances and apply invocation settings
   load explicitly selected PowerShell custom rules

Targets immybot-latest, which contains ImmyBot's existing runtime adaptations. No rule-instance cache, public API, or ImmyBot source change.

Evidence

Synthetic crowded-directory benchmark: 410 extra managed DLLs, 100 exported classes each, five fresh processes per variant, five warm-up calls and 30 measured calls per process. Same SDK, runtime, dependencies, and release configuration before and after; alternating build order. Timings below are medians of process medians.

Metric Before After
Warm discovery (Get-ScriptAnalyzerRule) 15.685 ms 0.252 ms
Warm full alias-analysis call 15.770 ms 0.363 ms
Assembly inspections per invocation 1,664 4
Unrelated assemblies loaded 410 0
Allocated bytes per analysis call 3,929,312 182,481

All 40 benchmark processes returned the same 69 rule names or the same alias diagnostic. These are local synthetic measurements, not editor latency measurements. The analysis sample executes one rule on gci; large scripts, all-rule execution, PSES debounce, and the actual ImmyBot publish directory remain outside the benchmark. Clean-directory cold timing did not improve consistently.

Measurement details, ranges, cold timing, memory, and reproduction commands. The reusable harness is tools/Measure-RuleDiscovery.ps1.

Before: all three new fresh-process tests fail: an invalid adjacent DLL aborts discovery; a managed unrelated DLL is loaded; a valid DLL with a missing base-type dependency aborts discovery.

After: all three pass, including checks for built-in diagnostics, formatting, and explicit PowerShell custom rules through both settings and custom-only invocation.

Testing

  • Both net6 / PSV7Release source builds succeed with the same four existing warnings.
  • Focused discovery, custom rules, settings, formatter, and new regression tests: 138 passed, 2 skipped.
  • Broader engine/rule suite: 1,276 passed, 148 skipped, 10 failures. All 10 also reproduce on the unchanged baseline: two sandbox-denied home-directory writes, three help checks for the newer ProgressAction common parameter, and five existing compatibility-profile assertions. The final additional missing-dependency regression was run separately and in the final focused suite.
  • PowerShell parser checks and git diff --check pass.

Merge Danger

Door: two-way; revert the commit to restore the old discovery behavior.

Blast Radius: Core discovery. A third-party compiled rule/logger merely placed beside the engine is no longer implicitly registered. Explicit PowerShell CustomRulePath behavior is preserved; compiled custom-rule support is not added to Core. The legacy full-framework MEF branch is unchanged. Fresh rule construction preserves settings isolation; no shared mutable cache is introduced.

Integration follow-up

No package is published by this PR. ImmyBot currently references private PSScriptAnalyzer 1.21.0. Package a new immutable version containing this fix, then update PSScriptAnalyzerPackageVersion in ImmyBot's Directory.Packages.props and verify the real editor. Existing NuGet packaging assets are on feature/submodule-to-nuget (b0bde41), separate from this PR's immybot-latest base.

@wopr-review wopr-review Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 1 suggestion

✅ Codebase Fit (1 suggestion, 2m)

✅ No findings

  • Observability (1m)
  • Bug Fix (1m)
  • PR Scope (<1m)

⏭️ Skipped

  • Concurrency: no shared state

Reviewed 20da7a1 in 2 min on vllm/reasoning. Comment /wopr review to run the skipped reviewers.

Comment thread Engine/ScriptAnalyzer.cs Resolved
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.

0 participants