Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
944cc45
Add issue 2205 regression test
Copilot Aug 19, 2026
d7d278c
Correct issue 2205 regression assertion
Copilot Aug 19, 2026
b8e7410
Add recursive issue 2205 regression scenario
Copilot Aug 19, 2026
3d791b2
Isolate issue 2205 regression fixture
Copilot Aug 19, 2026
3326269
Add issue 2205 failure regression
Copilot Aug 19, 2026
c51a892
Isolate issue 2205 failing regression
Copilot Aug 19, 2026
39b5356
Do not fail analysis on transient command lookup failures (issue 2205)
Copilot Aug 19, 2026
bc604c9
Address code review: evict only the faulted cache entry, clarify test…
Copilot Aug 19, 2026
9734b62
Merge pull request #1 from jessehouwing/copilot/create-unit-test-for-…
jessehouwing Aug 19, 2026
476e1a3
Serialize command info lookups on a single dedicated runspace
Copilot Aug 19, 2026
c4321d8
Make concurrency test safe against Helper singleton initialization order
Copilot Aug 19, 2026
ae52d7c
Address review: take the runspace lock on both dispose paths
Copilot Aug 19, 2026
469fd0a
Merge pull request #2 from jessehouwing/copilot/marshal-concurrent-ca…
jessehouwing Aug 19, 2026
8a75d6f
Merge branch 'PowerShell:main' into main
jessehouwing Sep 14, 2026
af4cb17
Add isolated cold and warm ScriptAnalyzer benchmark workflow
Copilot Sep 14, 2026
acd3f00
Expand performance comparison to Linux and semver repository workload
Copilot Sep 14, 2026
7a233e4
Preserve full PowerShell source tree in performance benchmarks
Copilot Sep 14, 2026
ac6dab8
Pin download-artifact to patched v4.3.0 commit
Copilot Sep 14, 2026
d82000d
Merge pull request #4 from jessehouwing/copilot/add-workflow-dispatch…
jessehouwing Sep 14, 2026
ada251b
Initial plan
Copilot Sep 14, 2026
36f9aef
Harden command lookup against Get-Command resolution failures
Copilot Sep 14, 2026
b13bae1
Avoid runspace races when resolving exported function parameters
Copilot Sep 14, 2026
e1ea2fb
Merge pull request #5 from jessehouwing/copilot/fix-benchmark-upstrea…
jessehouwing Sep 14, 2026
936b71f
Merge remote-tracking branch 'origin/main' into copilot/fix-benchmark…
Copilot Sep 14, 2026
1a928b6
Serialize command metadata reads with runspace command lookups
Copilot Sep 14, 2026
9ac604a
Merge pull request #7 from jessehouwing/copilot/fix-benchmark-fork-se…
jessehouwing Sep 14, 2026
b3d23b2
Record three-way benchmark requirement
Copilot Sep 14, 2026
ffdfa6f
Merge branch 'main' into main
bergmeister Sep 14, 2026
4125239
Merge branch 'main' into main
bergmeister Sep 14, 2026
37e07fd
Optimize synchronized metadata and add three-way performance benchmarks
Copilot Sep 14, 2026
aacafd8
Disable telemetry collection in performance comparisons
Copilot Sep 14, 2026
8cfecbf
Add consolidated performance matrix summary job
Copilot Sep 14, 2026
7b22321
Merge pull request #9 from jessehouwing/copilot/perf-additional-metri…
jessehouwing Sep 14, 2026
0d11274
Make PowerShell engine retries selectable and observable
Copilot Sep 14, 2026
028c67c
Fix spurious retries for unknown commands and verify retry modes
Copilot Sep 14, 2026
078fc8b
Centralize command metadata recovery and remove rule-level catches
Copilot Sep 14, 2026
7976235
Preserve negative caching while evicting exhausted lookup failures
Copilot Sep 14, 2026
c440009
Merge pull request #10 from jessehouwing/copilot/add-if-else-statements
jessehouwing Sep 14, 2026
1b37795
Update perf workflow for retry ifdef variants
Copilot Sep 14, 2026
95c089c
Merge pull request #11 from jessehouwing/copilot/add-perf-workflow-retry
jessehouwing Sep 14, 2026
ecebce4
Merge branch 'PowerShell:main' into main
jessehouwing Sep 14, 2026
f819022
Restore full benchmark matrix and distinct retry build variants
Copilot Sep 14, 2026
beeb3f9
Merge pull request #12 from jessehouwing/copilot/add-benchmark-compar…
jessehouwing Sep 14, 2026
c8e59b0
Remove engine retries and performance telemetry
jessehouwing Sep 14, 2026
d5e87f6
Remove perf branch from performance benchmark
jessehouwing Sep 14, 2026
7d4a11f
Merge pull request #13 from jessehouwing/perf
jessehouwing Sep 14, 2026
b8472db
Use C# 5 compatible syntax in Add-Type test fixtures
jessehouwing Sep 15, 2026
4d3b644
Skip the Get- prefix probe for command names containing a hyphen
jessehouwing Sep 17, 2026
c9e460d
Resolve commands the analyzed script defines against the script
jessehouwing Sep 17, 2026
6129442
Do not resolve member names as commands in UseShouldProcessCorrectly
jessehouwing Sep 17, 2026
b695606
Use a cross-platform command in the method-versus-command tests
jessehouwing Sep 17, 2026
a18d689
Call ShouldProcess in the fixture that declares support for it
jessehouwing Sep 17, 2026
2a36c98
Resolve commands across the files of a dot-sourced group
jessehouwing Sep 17, 2026
94ba0cf
Remove the command lookup instrumentation counters
jessehouwing Sep 17, 2026
6fcf7d5
Collect before each timed run in the performance harness
jessehouwing Sep 17, 2026
09f4323
Spend the tiering ramp before the warm measurement
jessehouwing Sep 17, 2026
13c287a
Merge branch 'PowerShell:main' into main
jessehouwing Sep 21, 2026
ebb8733
Address PR #2206 code review comments
jessehouwing Sep 22, 2026
322d661
Merge remote-tracking branch 'upstream/main'
jessehouwing Sep 22, 2026
597b01c
Make UseCorrectCasingForDotSourcedFiles disabled by default
jessehouwing Sep 22, 2026
63b4e71
Fix net462/C# 7.3 build: avoid switch-expression recursive patterns
jessehouwing Sep 22, 2026
7a26d8d
Fix Linux CI: restrict backslash-separator test cases to Windows
jessehouwing Sep 22, 2026
3f5bf19
Add tests for command info cache keys to verify case-insensitivity an…
jessehouwing Oct 7, 2026
317b274
Collect suppression declarations in a single AST traversal
PrzemyslawKlys Oct 8, 2026
1f068d3
Respect scope-qualified local function declarations
PrzemyslawKlys Oct 8, 2026
4400463
Keep command argument blocks in their caller scope
PrzemyslawKlys Oct 8, 2026
c24849d
Merge pull request #15 from PrzemyslawKlys/perf/suppression-declarati…
jessehouwing Oct 8, 2026
e9de0f9
Merge pull request #16 from PrzemyslawKlys/fix/scoped-local-function-…
jessehouwing Oct 8, 2026
75291c8
UseShouldProcessCorrectly: scope local function shadowing to the call…
jessehouwing Oct 9, 2026
00c0e60
Index brace and pipeline lookups during formatting
PrzemyslawKlys Oct 8, 2026
89bc5e1
Merge branch 'main' into main
jessehouwing Oct 13, 2026
68dbfad
Merge remote-tracking branch 'upstream/main'
jessehouwing Oct 23, 2026
c3c00e3
Address PR 2206 review follow-ups
jessehouwing Oct 23, 2026
8a74337
Move PR 2206 follow-up tests next to related existing tests
jessehouwing Oct 23, 2026
c366402
Document case-sensitive file system considerations
jessehouwing Oct 23, 2026
c9af6b7
Fix ambiguous GetCommandInfo reflection lookup in metadata tests
jessehouwing Oct 23, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
436 changes: 436 additions & 0 deletions .github/workflows/performance.yml

Large diffs are not rendered by default.

354 changes: 311 additions & 43 deletions Engine/CommandInfoCache.cs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Engine/CommandLookupKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public override int GetHashCode()
unchecked
{
int hash = 17;
hash = hash * 31 + Name.ToUpperInvariant().GetHashCode();
hash = hash * 31 + StringComparer.OrdinalIgnoreCase.GetHashCode(Name);
hash = hash * 31 + CommandTypes.GetHashCode();
return hash;
}
Expand Down
24 changes: 24 additions & 0 deletions Engine/CommandParameterSnapshot.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Collections.ObjectModel;
using System.Linq;
using System.Management.Automation;

namespace Microsoft.Windows.PowerShell.ScriptAnalyzer
{
/// <summary>Detached parameter facts, safe to consume without driving a PowerShell runspace.</summary>
public sealed class CommandParameterSnapshot
{
public string Name { get; }
public bool SwitchParameter { get; }
public ReadOnlyCollection<string> Aliases { get; }

internal CommandParameterSnapshot(ParameterMetadata parameter)
{
Name = parameter.Name;
SwitchParameter = parameter.SwitchParameter;
Aliases = new ReadOnlyCollection<string>(parameter.Aliases.ToArray());
}
}
}
416 changes: 416 additions & 0 deletions Engine/DotSourceScope.cs

Large diffs are not rendered by default.

98 changes: 83 additions & 15 deletions Engine/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,15 @@ public PSModuleInfo GetModuleManifest(string filePath, out IEnumerable<ErrorReco
return psModuleInfo;
}

/// <summary>Shares validation between built-in rules during one syntax-tree analysis only.</summary>
public PSModuleInfo GetModuleManifestForAnalysis(string filePath, out IEnumerable<ErrorRecord> errorRecords)
{
var cache = ModuleManifestAnalysisCache.Current;
return cache == null
? GetModuleManifest(filePath, out errorRecords)
: cache.Get(this, filePath, out errorRecords);
}

/// <summary>
/// Checks if the error record is MissingMemberException
/// </summary>
Expand Down Expand Up @@ -399,18 +408,22 @@ public HashSet<string> GetExportedFunction(Ast ast)
List<string> exportFunctionsCmdlet = Helper.Instance.CmdletNameAndAliases("export-modulemember");

// find functions exported
IEnumerable<Ast> cmdAsts = ast.FindAll(item => item is CommandAst
&& exportFunctionsCmdlet.Contains((item as CommandAst).GetCommandName(), StringComparer.OrdinalIgnoreCase), true);

CommandInfo exportMM = Helper.Instance.GetCommandInfo("export-modulemember", CommandTypes.Cmdlet);

// switch parameters
IEnumerable<ParameterMetadata> switchParams = (exportMM != null) ? exportMM.Parameters.Values.Where<ParameterMetadata>(pm => pm.SwitchParameter) : Enumerable.Empty<ParameterMetadata>();
var cmdAsts = ast.FindAll(item => item is CommandAst
&& exportFunctionsCmdlet.Contains((item as CommandAst).GetCommandName(), StringComparer.OrdinalIgnoreCase), true).ToArray();
if (cmdAsts.Length == 0)
{
return exportedFunctions;
}

if (exportMM == null)
// Export-ModuleMember has no dynamic parameters. Resolve names from its static
// metadata instead of ResolveParameter(), which re-enters the cached command's
// runspace and races with command lookups and metadata queries on other rule threads.
var parameters = GetCommandParameterSnapshot("Microsoft.PowerShell.Core\\Export-ModuleMember", CommandTypes.Cmdlet);
if (parameters == null)
{
return exportedFunctions;
}
var switchParams = parameters.Values.Where(pm => pm.SwitchParameter);

foreach (CommandAst cmdAst in cmdAsts)
{
Expand All @@ -429,7 +442,20 @@ public HashSet<string> GetExportedFunction(Ast ast)
if (ceAst is CommandParameterAst)
{
var paramAst = ceAst as CommandParameterAst;
var param = exportMM.ResolveParameter(paramAst.ParameterName);
CommandParameterSnapshot param;
if (!parameters.TryGetValue(paramAst.ParameterName, out param))
{
param = parameters.Values.FirstOrDefault(pm =>
pm.Aliases.Contains(paramAst.ParameterName, StringComparer.OrdinalIgnoreCase));
if (param == null)
{
var matches = parameters.Values.Where(pm =>
pm.Name.StartsWith(paramAst.ParameterName, StringComparison.OrdinalIgnoreCase)
|| pm.Aliases.Any(alias => alias.StartsWith(paramAst.ParameterName, StringComparison.OrdinalIgnoreCase)))
.Take(2).ToArray();
param = matches.Length == 1 ? matches[0] : null;
}
}

if (param == null)
{
Expand Down Expand Up @@ -613,7 +639,7 @@ public bool IsKnownCmdletFunctionOrExternalScript(CommandAst cmdAst, out Command
return false;
}

commandInfo = GetCommandInfo(cmdAst.GetCommandName());
commandInfo = GetCommandInfo(cmdAst.GetCommandName(), callSite: cmdAst);
if (commandInfo == null)
{
return false;
Expand Down Expand Up @@ -666,9 +692,47 @@ public bool PositionalParameterUsed(CommandAst cmdAst, bool moreThanTwoPositiona
/// <param name="commandType"></param>
/// <param name="bypassCache"></param>
/// <returns></returns>
public CommandInfo GetCommandInfo(string name, CommandTypes? commandType = null, bool bypassCache = false)
public CommandInfo GetCommandInfo(string name, CommandTypes? commandType, bool bypassCache)
{
return GetCommandInfo(name, commandType, bypassCache, null);
}

/// <summary>
/// Given a command's name, checks whether it exists, taking the call site into account.
/// </summary>
public CommandInfo GetCommandInfo(string name, CommandTypes? commandType = null, bool bypassCache = false, Ast callSite = null)
{
return CommandInfoCache.GetCommandInfo(name, commandTypes: commandType, bypassCache: bypassCache);
return CommandInfoCache.GetCommandInfo(name, commandTypes: commandType, bypassCache: bypassCache, callSite: callSite);
}

/// <summary>
/// Retrieves command parameters with centralized recovery; returns null when metadata is unavailable.
/// </summary>
public Dictionary<string, ParameterMetadata> GetCommandParameters(
string name, CommandTypes? commandType = null, bool bypassCache = false, Ast callSite = null)
{
return CommandInfoCache.GetCommandParameters(name, commandType, bypassCache, callSite);
}

/// <summary>
/// Retrieves command parameter sets with centralized recovery; returns null when metadata is unavailable.
/// </summary>
public ReadOnlyCollection<CommandParameterSetInfo> GetCommandParameterSets(string name, Ast callSite = null)
{
return CommandInfoCache.GetCommandParameterSets(name, callSite);
}

/// <summary>Gets detached parameter facts or null when unavailable; only static cmdlet metadata is cached.</summary>
public IReadOnlyDictionary<string, CommandParameterSnapshot> GetCommandParameterSnapshot(
string name, CommandTypes? commandType = null, bool bypassCache = false, Ast callSite = null)
{
return CommandInfoCache.GetParameterSnapshot(name, commandType, bypassCache, callSite);
}

/// <summary>Gets the mandatory parameter summary under a single runspace lock, or null when unavailable.</summary>
public IReadOnlyList<string> GetMandatoryParameterNames(string name, Ast callSite = null)
{
return CommandInfoCache.GetMandatoryParameterNames(name, callSite);
}

/// <summary>
Expand Down Expand Up @@ -1142,24 +1206,28 @@ public Dictionary<string, List<RuleSuppression>> GetRuleSuppression(Ast ast)
ruleSuppressionList.AddRange(RuleSuppression.GetSuppressions(sbAst.ParamBlock.Attributes, sbAst.Extent.StartOffset, sbAst.Extent.EndOffset, sbAst));
}

// Walk the tree once, retaining the existing function/class/configuration processing order.
var declarationAsts = ast.FindAll(item => item is FunctionDefinitionAst
|| item is TypeDefinitionAst || item is ConfigurationDefinitionAst, true).ToArray();

// Get rule suppression from functions
IEnumerable<FunctionDefinitionAst> funcAsts = ast.FindAll(item => item is FunctionDefinitionAst, true).Cast<FunctionDefinitionAst>();
IEnumerable<FunctionDefinitionAst> funcAsts = declarationAsts.OfType<FunctionDefinitionAst>();

foreach (var funcAst in funcAsts)
{
ruleSuppressionList.AddRange(GetSuppressionsFunction(funcAst));
}

// Get rule suppression from classes
IEnumerable<TypeDefinitionAst> typeAsts = ast.FindAll(item => item is TypeDefinitionAst, true).Cast<TypeDefinitionAst>();
IEnumerable<TypeDefinitionAst> typeAsts = declarationAsts.OfType<TypeDefinitionAst>();

foreach (var typeAst in typeAsts)
{
ruleSuppressionList.AddRange(GetSuppressionsClass(typeAst));
}

// Get rule suppression from configuration definitions
IEnumerable<ConfigurationDefinitionAst> configDefAsts = ast.FindAll(item => item is ConfigurationDefinitionAst, true).Cast<ConfigurationDefinitionAst>();
IEnumerable<ConfigurationDefinitionAst> configDefAsts = declarationAsts.OfType<ConfigurationDefinitionAst>();

foreach (var configDefAst in configDefAsts)
{
Expand Down
Loading