-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Produce less string allocs while formatting documents #73452
Conversation
if (!previousToken.ContainsAnnotations && !currentToken.ContainsAnnotations) | ||
return false; | ||
|
||
if (!previousToken.HasTrailingTrivia && !currentToken.HasLeadingTrivia) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just formatting so i could understand the code.
=> t == null; | ||
|
||
public static bool IsNotNull<T>(T t) where T : class | ||
=> !IsNull(t); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not called.
|
||
return previousToken.TrailingTrivia.HasAnyWhitespaceElasticTrivia() || currentToken.LeadingTrivia.HasAnyWhitespaceElasticTrivia(); | ||
} | ||
|
||
public static bool IsNull<T>(T t) where T : class | ||
=> t == null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mostly pointless. so inlined.
@@ -53,7 +54,8 @@ public static bool ContainsElasticTrivia(this SuppressOperation operation, Token | |||
var endToken = tokenStream.GetTokenData(operation.EndToken); | |||
var previousToken = endToken.GetPreviousTokenData(); | |||
|
|||
return tokenStream.GetTriviaData(startToken, nextToken).TreatAsElastic || tokenStream.GetTriviaData(previousToken, endToken).TreatAsElastic; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getting TriviaData is not cheap. It allocates up front (The substring between tokesn). I looked into changing that, but it was non-trivial. so thsi was the expedient solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could someone please tell me what perf tool is being used in those screenshots? |
|
Takes us from:
to:
(we actually call this in several places, which is why we get 800 MB drop).