Skip to content

Check the syntax kind instead of the wrapper type in GetIdentifier - #9853

Open
alexander-efremov wants to merge 1 commit into
SonarSource:masterfrom
alexander-efremov:perf/get-identifier-kind-checks
Open

alexander-efremov wants to merge 1 commit into
SonarSource:masterfrom
alexander-efremov:perf/get-identifier-kind-checks

Conversation

@alexander-efremov

Copy link
Copy Markdown

What

GetIdentifier matched newer syntax nodes (local functions, file-scoped namespaces, new(), ref types, subpatterns and others) with XxxWrapper.IsInstance. Each call does GetType() and a ConcurrentDictionary lookup. It now compares RawKind with IsKind(SyntaxKindEx.Xxx).

Why

Each of these wrapped types has exactly one syntax kind, so the result is the same. A node that matches none of the earlier arms went through all seven lookups.

Measurements

  • GetIdentifier on every node of a 820k-node C# code base, 30 passes, 3 runs per build: median 39.2-43.4 ms before, 34.4-34.8 ms after (about 13% less). Same results for every node.
  • End to end (csc on a large test project, 8 interleaved runs) the difference is within noise.

Tests

  • SyntaxNodeExtensionsTest, BuilderPatternConditionTest, MemberDescriptorTest: net10.0 387 passed; net48 382 passed.

Each wrapper IsInstance call looks up the node type in a dictionary. Every
wrapped type here has exactly one syntax kind, so comparing the kind gives
the same result for the cost of an integer comparison.
@gitar-bot

gitar-bot Bot commented Oct 4, 2026

Copy link
Copy Markdown
Code Review ✅ Approved

🟢 Low risk · Seven wrapper checks become syntax-kind comparisons in one identifier helper.

Replaces wrapper type checks with direct syntax kind comparisons in GetIdentifier, improving performance by ~13% on large codebases while maintaining identical behavior. No issues found.

Review coverage

🧪 Functional validation No results

📋 Rules No rules evaluated

Cross-repo coverage 1 repository selected

🤖 Auto-approval Not enabled · Set up

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Counting what did not apply, without listing it.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

@sonar-platform-bot

Copy link
Copy Markdown

This pull request is being closed because it has been identified as stale.

This branch has not been deployed

No deployments
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