Repository navigation
Check the syntax kind instead of the wrapper type in GetIdentifier - #9853
Open
alexander-efremov wants to merge 1 commit into
Open
alexander-efremov wants to merge 1 commit into
alexander-efremov wants to merge 1 commit into
Conversation
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.
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 Review coverage🧪 Functional validation No results 📋 Rules No rules evaluated Cross-repo coverage 1 repository selected 🤖 Auto-approval Not enabled · Set up OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Gitar |
|
This pull request is being closed because it has been identified as stale. |
This branch has not been deployed
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.
What
GetIdentifiermatched newer syntax nodes (local functions, file-scoped namespaces,new(),reftypes, subpatterns and others) withXxxWrapper.IsInstance. Each call doesGetType()and aConcurrentDictionarylookup. It now comparesRawKindwithIsKind(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
GetIdentifieron 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.Tests
SyntaxNodeExtensionsTest,BuilderPatternConditionTest,MemberDescriptorTest: net10.0 387 passed; net48 382 passed.