Repository navigation
Reduce the time spent in MA0182 - #1636
Merged
Merged
Conversation
The rule called SemanticModel.GetEnclosingSymbol for every operation that references a type of the analyzed assembly, to ignore the references a type makes to itself. This call is much more expensive than the rest of the analysis, and it was made again and again for the types that are only referenced by themselves, as they are never added to the processed types. The operation callbacks now use the containing symbol provided by the analysis context, which is free. A type that references itself only from an attribute applied to a parameter of its own primary constructor is now reported, as the reference is now attributed to the type instead of its containing namespace or type.
meziantou
enabled auto-merge (squash)
October 13, 2026 14:42
This was referenced Oct 13, 2026
kivilev
pushed a commit
to kivilev/plsql-developer-text-tools
that referenced
this pull request
Oct 13, 2026
Updated [Meziantou.Analyzer](https://github.com/meziantou/Meziantou.Analyzer) from 3.0.290 to 3.0.303. <details> <summary>Release notes</summary> _Sourced from [Meziantou.Analyzer's releases](https://github.com/meziantou/Meziantou.Analyzer/releases)._ ## 3.0.303 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.303> ## What's Changed * MA0100: do not look up GetAwaiter for the types that cannot be awaited by @meziantou in meziantou/Meziantou.Analyzer#1635 * Reduce the time spent in MA0154, MA0218 and MA0219 by @meziantou in meziantou/Meziantou.Analyzer#1638 * Reduce the time spent in MA0182 by @meziantou in meziantou/Meziantou.Analyzer#1636 * Reduce the time spent in MA0134 by @meziantou in meziantou/Meziantou.Analyzer#1637 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.302...3.0.303 ## 3.0.302 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.302> ## What's Changed * Reduce the time spent in MA0001, MA0002, MA0011, MA0026, MA0074 and MA0150 by @meziantou in meziantou/Meziantou.Analyzer#1634 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.301...3.0.302 ## 3.0.301 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.301> ## What's Changed * Reduce the CPU and the memory used by MA0202 by @meziantou in meziantou/Meziantou.Analyzer#1633 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.300...3.0.301 ## 3.0.300 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.300> ## What's Changed * MA0015, MA0043: do not enumerate all the symbols in scope by @meziantou in meziantou/Meziantou.Analyzer#1632 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.299...3.0.300 ## 3.0.299 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.299> ## What's Changed * MA0031: do not suggest Skip(n).Any() when the value is not a constant by @meziantou in meziantou/Meziantou.Analyzer#1631 * chore(deps): update all dependencies by @renovate[bot] in meziantou/Meziantou.Analyzer#1627 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.298...3.0.299 ## 3.0.298 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.298> ## What's Changed * chore(deps): update dependency meziantou.framework.roslyn to 1.2.1 by @renovate[bot] in meziantou/Meziantou.Analyzer#1629 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.297...3.0.298 ## 3.0.297 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.297> ## What's Changed * Update Meziantou.NET.Sdk to 1.0.183 and use its SharedHttpClient by @meziantou in meziantou/Meziantou.Analyzer#1628 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.296...3.0.297 ## 3.0.296 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.296> ## What's Changed * Add tests for non-culture-sensitive string methods by @meziantou in meziantou/Meziantou.Analyzer#1626 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.295...3.0.296 ## 3.0.295 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.295> ## What's Changed * MA0002: treat the xunit assertions that take an IEqualityComparer<T> as ordinal with report_only_non_ordinal by @vencyk in meziantou/Meziantou.Analyzer#1625 ## New Contributors * @vencyk made their first contribution in meziantou/Meziantou.Analyzer#1625 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.294...3.0.295 ## 3.0.294 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.294> ## What's Changed * Do not suggest instance members in static contexts in MA0166/MA0167 by @meziantou in meziantou/Meziantou.Analyzer#1623 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.293...3.0.294 ## 3.0.293 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.293> ## What's Changed * Check for a set instance only before an MA0002 report by @alexander-efremov in meziantou/Meziantou.Analyzer#1622 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.292...3.0.293 ## 3.0.292 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.292> ## What's Changed * Cache LookupSymbols results in OverloadFinder by @alexander-efremov in meziantou/Meziantou.Analyzer#1621 * chore(deps): update all dependencies to 1.0.179 by @renovate[bot] in meziantou/Meziantou.Analyzer#1618 ## New Contributors * @alexander-efremov made their first contribution in meziantou/Meziantou.Analyzer#1621 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.291...3.0.292 ## 3.0.291 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.291> ## What's Changed * Do not merge is patterns declaring variables in the MA0194 code fix by @meziantou in meziantou/Meziantou.Analyzer#1620 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.290...3.0.291 Commits viewable in [compare view](meziantou/Meziantou.Analyzer@3.0.290...3.0.303). </details> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This was referenced Oct 13, 2026
This was referenced Oct 16, 2026
Merged
Merged
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
MA0182 (
AvoidUnusedInternalTypesAnalyzer) shows up as one of the slowest rules. For every operation that references a type of the analyzed assembly (invocation, member reference, object creation, ...), the rule calledSemanticModel.GetEnclosingSymbolto ignore the references a type makes to itself. That call costs 10-100 µs each and accounted for half or more of the time spent in the callbacks of the rule.It is worst for the types that are only referenced by themselves, as they are never added to the processed types: a public class that calls its own helpers (test classes, controllers) pays it on every reference to one of its own members.
What
The operation callbacks now use
OperationAnalysisContext.ContainingSymbol, which Roslyn already provides, instead of querying the semantic model. The lazyReferenceLocationstruct is not needed anymore, so it is removed.Measurements
Measured by running the analyzer on the test project of this repository (Roslyn 5.9) with
CompilationWithAnalyzersandlogAnalyzerExecutionTime. The machine was under heavy load, so the medians are noisy, but the direction was the same in every run.Behavior change
A type that references itself only from an attribute applied to a parameter of its own primary constructor is now reported. It was considered as used before, because
GetEnclosingSymbolreturns the containing namespace or type for that position:This is consistent with the same attribute applied to the type itself, which was already reported (
InternalClassAttributeTypeOfOwnClass_Diagnostic).I compared the old and the new reference location on every operation of the analyzer project and of the test project (about 79,000 operations). The only difference is the base call of a primary constructor, which has no effect on the diagnostics. The diagnostics reported on both projects are the same before and after.
Tests
InternalClassReferencingItselfInPrimaryConstructor_Diagnosticfails without the change.AvoidUnusedInternalTypesAnalyzerTestspasses with every supported Roslyn version (119 tests with 4.8 and 4.14, 125 with 5.0, 5.6 and 5.9). The full test suite was not run locally.dotnet run --project src/DocumentationGeneratorproduces no change.