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

Remove array allocations for formatting rules. #73458

Merged
merged 24 commits into from
May 14, 2024

Conversation

CyrusNajmabadi
Copy link
Member

Removes effectively all of these allocatinos:

image

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner May 13, 2024 22:13
@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
@@ -30,10 +31,10 @@ internal static IEnumerable<AbstractFormattingRule> GetDefaultFormattingRules(IS
/// <param name="cancellationToken">An optional cancellation token.</param>
/// <returns>The formatted tree's root node.</returns>
public static SyntaxNode Format(SyntaxNode node, ISyntaxFormatting syntaxFormattingService, SyntaxFormattingOptions options, CancellationToken cancellationToken)
=> Format(node, [node.FullSpan], syntaxFormattingService, options, rules: null, cancellationToken: cancellationToken);
=> Format(node, [node.FullSpan], syntaxFormattingService, options, rules: default, cancellationToken: cancellationToken);
Copy link
Member Author

Choose a reason for hiding this comment

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

changed things to be explicitly ImmutableArrays, not IEnumerables. So lots of fallout of that.

@@ -45,21 +46,35 @@ internal abstract partial class AbstractFormatEngine
internal readonly SyntaxFormattingOptions Options;
internal readonly TreeData TreeData;

private static readonly object s_gate = new();
private static (ImmutableArray<AbstractFormattingRule> formattingRules, SyntaxFormattingOptions options, ChainedFormattingRules chainedRules) s_lastRulesAndOptions;
Copy link
Member Author

Choose a reason for hiding this comment

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

this is the crux of hte change.

}

return true;
}).ToImmutableArray();
});
Copy link
Member Author

Choose a reason for hiding this comment

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

i want an analyzer for this.

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 merged commit 9b6dd87 into dotnet:main May 14, 2024
25 checks passed
@CyrusNajmabadi CyrusNajmabadi deleted the arrayAllocs branch May 14, 2024 02:27
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone May 14, 2024
@Cosifne Cosifne modified the milestones: Next, 17.11 P2 May 28, 2024
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.

3 participants