Skip to content
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

Merged
merged 1 commit into from
May 13, 2024

Conversation

CyrusNajmabadi
Copy link
Member

Takes us from:

image

to:

image

(we actually call this in several places, which is why we get 800 MB drop).

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner May 13, 2024 20:40
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels May 13, 2024
@CyrusNajmabadi CyrusNajmabadi requested a review from ToddGrun May 13, 2024 20:41
if (!previousToken.ContainsAnnotations && !currentToken.ContainsAnnotations)
return false;

if (!previousToken.HasTrailingTrivia && !currentToken.HasLeadingTrivia)
Copy link
Member Author

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);
Copy link
Member Author

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;
Copy link
Member Author

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;
Copy link
Member Author

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.

Copy link
Contributor

@ToddGrun ToddGrun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@CyrusNajmabadi CyrusNajmabadi enabled auto-merge May 13, 2024 21:18
@CyrusNajmabadi CyrusNajmabadi merged commit 3e45d72 into dotnet:main May 13, 2024
25 checks passed
@CyrusNajmabadi CyrusNajmabadi deleted the formattingStrings branch May 13, 2024 22:04
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone May 13, 2024
@Cosifne Cosifne modified the milestones: Next, 17.11 P2 May 28, 2024
@lonix1
Copy link

lonix1 commented May 30, 2024

Could someone please tell me what perf tool is being used in those screenshots?

@ToddGrun
Copy link
Contributor

Could someone please tell me what perf tool is being used in those screenshots?

See https://github.com/microsoft/perfview/releases

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants