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

Avoid unnecessary full tree walks in the simplifier system #73473

Merged
merged 4 commits into from
May 15, 2024

Conversation

CyrusNajmabadi
Copy link
Member

Drops us from:
image

to:

image

Note: there are much more wins from this as this basically drops practically every syntax node kind. All up this lowers us 25% from:

image

to:

image

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner May 14, 2024 21:45
@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 14, 2024
@@ -166,6 +165,9 @@ bool isNodeOrTokenOutsideSimplifySpans(SyntaxNodeOrToken nodeOrToken)
}

return document;

bool IsNodeOrTokenOutsideSimplifySpans(SyntaxNodeOrToken nodeOrToken)
Copy link
Contributor

Choose a reason for hiding this comment

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

IsNodeOrTokenOutsideSimplifySpans

nit: just noticed the executeSerially flag is just supposed to be a debugger friendly bit, but it complicates things below. I'd be totally ok with deleting that as I think it actually complicates the code more than it helps.

Copy link
Member Author

Choose a reason for hiding this comment

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

can do later (it's already being touched in #73471)

var hasImportsToSimplify = root != originalRoot;

if (hasImportsToSimplify)
{
document = document.WithSyntaxRoot(root);
semanticModel = await document.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(false);
root = await semanticModel.SyntaxTree.GetRootAsync(cancellationToken).ConfigureAwait(false);
root = (TCompilationUnitSyntax)await document.GetRequiredSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

root =

dumb question, this does actually change the value of root, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes. when we set the root, we get a new syntax tree with the root parented by that (that involves a fork of the red node, but it reuses the underlying green node).

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 a26bed7 into dotnet:main May 15, 2024
25 checks passed
@CyrusNajmabadi CyrusNajmabadi deleted the importsWalk branch May 15, 2024 00:12
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone May 15, 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