Repository navigation
Conversation
There was a problem hiding this comment.
Good allocation-reduction PR. The core optimizations (static lambdas, depth tracking instead of chain-per-node, collection reuse, assembly-scoped namespace) are sound and should meaningfully reduce GC pressure during analysis.
Key findings:
-
Behavioral change (medium): The switch from Compilation.GlobalNamespace to Assembly.GlobalNamespace is correct but is a semantic change — please document it in the PR description and consider a test.
-
Robustness (medium): The chain reconstruction in ReportTransitiveViolation uses a direct dictionary indexer. If BFS invariants are ever violated, this throws KeyNotFoundException and silently disables the analyzer. Recommend using TryGetValue with a graceful bail-out — analyzers must never crash.
-
ConcurrentBag enumeration: Removing .ToArray() before enumeration is fine — ConcurrentBag.GetEnumerator() takes an internal snapshot. No correctness issue.
-
Depth semantics: Starting at depth=2 for direct callees correctly mirrors the old chain.Count=2 behavior. Equivalent.
Overall: well-structured changes with clear perf wins. The two items above are worth addressing before merge.
Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
awmgmcpg
To allow these domains, add them to the
network.allowedlist in your workflow frontmatter:
network:
allowed:
- defaults
- "awmgmcpg"See Network Configuration for more information.
Generated by Expert Code Review (on open) for #14388 · 62.4 AIC · ⌖ 5.21 AIC · ⊞ 4.8K
| @@ -236,7 +235,7 @@ private static void AnalyzeTransitiveViolations( | |||
| { | |||
There was a problem hiding this comment.
Behavioral change: Assembly.GlobalNamespace vs Compilation.GlobalNamespace
This scopes task discovery to the current assembly only. This is almost certainly the correct behavior (we shouldn't analyze tasks defined in referenced assemblies), but it's a semantic change that should be called out in the PR description. Are there tests that validate task types in referenced assemblies are NOT analyzed? If not, consider adding one to lock in this intentional behavior change.
| var chainWithApi = new List<string>(chain) { violation.ApiDisplayName }; | ||
| var chainStr = string.Join(" → ", chainWithApi); | ||
| var chain = new List<ISymbol>(); | ||
| ISymbol current = violatingSymbol; |
There was a problem hiding this comment.
Robustness: missing guard against infinite loop in chain reconstruction.
If parentBySymbol doesn't contain a path back to taskMethod.OriginalDefinition (e.g., due to a bug or an unexpected symbol equality issue), this while loop will throw KeyNotFoundException. While this should never happen given the BFS invariants, a defensive check would be prudent for an analyzer (analyzers should never crash):
while (!SymbolEqualityComparer.Default.Equals(current, taskMethod.OriginalDefinition))
{
chain.Add(current);
if (!parentBySymbol.TryGetValue(current, out current!))
{
// Shouldn't happen — bail out gracefully
return;
}
}This avoids a potential unhandled exception that would silently disable the analyzer for the rest of the compilation.
Add a BenchmarkDotNet harness that compares analyzer no-op cost, per-diagnostic cost, 1/10/100 scaling, and suppressor behavior. Add task-analyzer authoring guidance derived from the existing analyzer PRs, require benchmark comparisons to drive an optimize-or-stop decision, and route task-author diagnostics away from engine error guidance. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 412a1a5f-d793-47bc-81f5-b341fd2b1cd7
Fail benchmark execution immediately when an analyzer throws, add compliant-task zero-diagnostic benchmarks alongside the early-exit no-op cases, and mark the benchmark project as non-shipping. Update the analyzer-authoring skill so new analyzer classes participate in both fixed-cost benchmark paths. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 412a1a5f-d793-47bc-81f5-b341fd2b1cd7
5983096 to
4373751
Compare
7d05a45 to
cda392d
Compare
Keep BenchmarkDotNet classes in AnalyzerBenchmarks.cs, move runner and compilation mechanics to AnalyzerBenchmarkInfrastructure.cs, and isolate analyzer registrations and source generation in AnalyzerScenarios.cs. Update the authoring skill so ordinary analyzer additions touch only the scenario definitions. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 412a1a5f-d793-47bc-81f5-b341fd2b1cd7
The analyzer benchmark harness identified MSBuildTask0005 as a fixed-cost allocation outlier: 2.73 MB for one diagnostic and 3.13 MB for ten, versus roughly 0.35-0.84 MB for the other rules. Limit task discovery to source symbols, reuse breadth-first-search state, store parent links instead of copying call-chain lists, format chains only when reporting, and remove LINQ from task filtering. Focused post-change runs allocate 0.54 MB, 0.95 MB, and 5.05 MB for 1, 10, and 100 diagnostics, reductions of 80%, 70%, and 30%. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 412a1a5f-d793-47bc-81f5-b341fd2b1cd7
cda392d to
4d45ac1
Compare
6e79245 to
6e10f71
Compare
Fixes #
Context
This PR applies the benchmark-driven workflow from #14387 to MSBuildTask0005 (
TransitiveCallChainAnalyzer).The baseline full-harness comparison identified a clear fixed-cost allocation outlier. At one diagnostic, MSBuildTask0005 allocated 2.73 MB while the other analyzer rules allocated approximately 0.35-0.52 MB. At ten diagnostics it allocated 3.13 MB while peers allocated approximately 0.63-1.26 MB.
Decision: optimize the analyzer, then stop once a same-environment comparison shows that its time, allocations, and scaling are in line with the existing rules.
Changes Made
ConcurrentDictionary.GetOrAddfactories to avoid closure allocations.Testing
The final same-run comparison places MSBuildTask0005 within the existing analyzer range at every scale, so no further specialization is warranted.
Notes
This PR depends on #14387 and should be reviewed as the second PR in the sequence.
The original baseline used .NET 10.0.8 and the final run used .NET 10.0.10. Managed allocations are therefore the primary before/after metric; the final timing assessment compares MSBuildTask0005 with all peers measured in the same .NET 10.0.10 run.