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

Don't run code in the async/await highlighter unless on one of those keywords. #73721

Merged
merged 11 commits into from
May 26, 2024

Conversation

CyrusNajmabadi
Copy link
Member

Addresses about half the cost of keyword highlighting.

image

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner May 26, 2024 06:42
@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 26, 2024
@CyrusNajmabadi
Copy link
Member Author

@ToddGrun ptal.

AddTouchingTokens(root, position, tokens, findInsideTrivia: false);
AddTouchingTokens(root, position, ref tokens, findInsideTrivia: true);
if (_findInsideTrivia)
AddTouchingTokens(root, position, ref tokens, findInsideTrivia: false);
Copy link
Member Author

Choose a reason for hiding this comment

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

no point going into trivia for most highlighters. can update others as appropraite.

// We only look at a max of 4 tokens (two trivia, and two non-trivia), so a temp-array is ideal here
using var touchingTokens = TemporaryArray<SyntaxToken>.Empty;
AddTouchingTokens(root, position, ref touchingTokens.AsRef());
if (!ContainsHighlightableToken(ref touchingTokens.AsRef()))
Copy link
Member Author

Choose a reason for hiding this comment

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

the async/await highlighter si not well written. it does all sorts of unnecessary work even when not on an appropraite keyword. this allows us to early bail out here and not do any of that work.

internal class IfStatementHighlighter : AbstractKeywordHighlighter<IfStatementSyntax>
[method: ImportingConstructor]
[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
internal sealed class IfStatementHighlighter() : AbstractKeywordHighlighter<IfStatementSyntax>(findInsideTrivia: false)
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 picked the highlighters to update based on if i saw the in the traces.

@ToddGrun
Copy link
Contributor

        tokens.Add(token);

dumb question:

Could this method to also handle the _findInsideTrivia case and use the FindToken results so it wouldn't need to walk the as much of the tree for the _findInsideTrivia case, or is that more complexity than it's worth? ie, something like:

var token = root.FindToken(position, findInsideTrivia: false);
if (!tokens.Contains(token))
    tokens.Add(token);

if (_findInsideTrivia)
{
    token = token.Parent.FindToken(position, findInsideTrivia: true);
    if (!tokens.Contains(token))
        tokens.Add(token);    
}  
...

Refers to: src/Features/Core/Portable/Highlighting/Keywords/AbstractKeywordHighlighter.cs:94 in b7594de. [](commit_id = b7594de, deletion_comment = False)

or SyntaxKind.WhileKeyword
or SyntaxKind.BreakKeyword
or SyntaxKind.ContinueKeyword
or SyntaxKind.SemicolonToken);
Copy link
Contributor

Choose a reason for hiding this comment

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

SyntaxKind.SemicolonToken

Can you clarify what this means in practice? If a semicolon is at the caret position, this highlighter will always be asked?

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. that's correct. that's because the loop highlighter will highlight if you're next to things like break; that's ok. this is still a tiny subset of all tokens.

Copy link
Member Author

Choose a reason for hiding this comment

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

the main goal here is to stop runnin all these highlighters unnecessarily on tokens they will never report results for. that's just pointless.

@CyrusNajmabadi
Copy link
Member Author

Could this method to also handle the _findInsideTrivia case and use the FindToken results so it wouldn't need to walk the as much of the tree for the _findInsideTrivia case, or is that more complexity than it's worth? ie, something like:

It definitely could/should. But baby steps based on traces :)

@ToddGrun
Copy link
Contributor

Fair enough, doesn't hurt to ask :)


In reply to: 2132367763

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 0a74148 into dotnet:main May 26, 2024
25 checks passed
@CyrusNajmabadi CyrusNajmabadi deleted the asyncAwaitPerf branch May 26, 2024 20:37
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone May 26, 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.

None yet

3 participants