dotnet/roslyn

SyntaxToken.GetNextToken is very slow for long Child/Token lists - which causes SyntaxNormalizer to be slow as well

Open

#72.861 aperta il 3 apr 2024

Vedi su GitHub
 (1 commento) (0 reazioni) (0 assegnatari)C# (4257 fork)batch import
Area-CompilersBughelp wanted

Metriche repository

Star
 (20.414 star)
Metriche merge PR
 (Merge medio 6g 17h) (256 PR mergiate in 30 g)

Descrizione

Version Used:

Steps to Reproduce: Parse the following code with a long array initializer - and Normalize whitespace.

Expected Behavior: It should terminate in a reasonable time.

Actual Behavior: Computes like forever


The performance hit seems to be caused mainly by SyntaxNavigator.GetNextToken which is called by SyntaxNormalizer.GetNextRelevantToken. To skip the previous tokens it simply iterates over all childs and tokens until it finds itself. For small token lists this is fine - but for long lists this algorithm is very bad. Couldn't we do for example something like binary search based on the token positon / span?

In addition: To iterate over the nodes it calls SyntaxNode.ChildNodesAndTokens() - which needs to compute the count all the time.

Close to that function is ChildThatContainsPosition() which seems to be very much faster - perhaps we could use that function ...

Guida contributor