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

Add dedicated bit for indicating if a node itself has annotations (versus its children). #72104

Merged
merged 8 commits into from
Feb 15, 2024

Conversation

CyrusNajmabadi
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi commented Feb 14, 2024

Followup to #72070. Draft while that is in review.

This helps avoid expensive conditionalweaktable lookups. This is especially useful when examining trees for things like elastic trivia. We end up seeing that some child has annotations deep in a node. But we need to examine all the nodes down to the child to see if they have annotations on them (since we can't distinguish 'has' vs 'contains'). For large trees, where all the tokens have elastic trivia, this is incredibly expensive.

@CyrusNajmabadi CyrusNajmabadi marked this pull request as ready for review February 15, 2024 18:48
System.Diagnostics.Debug.Assert(annotations.Length != 0, "we should return nonempty annotations or NoAnnotations");
return annotations;
}
}
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 meat of the change. In the past, we'd end up lookign at nodes that didn't actually have annotations on htem, because they had a child somewhere deep under them with annotations. This was very expensive as CWT lookups are not cheap. For tree rewrites, when rewriting nodes , we look at the old node to copy annotations over. And this meant almost always doing this work just if a deep child token had an annotation. now we only need to do the work on nodes that actually have annotations on them themselves.

@CyrusNajmabadi
Copy link
Member Author

@RikkiGibson @sharwell @333fred this is ready for review.

@CyrusNajmabadi CyrusNajmabadi merged commit c123404 into dotnet:main Feb 15, 2024
24 checks passed
@CyrusNajmabadi CyrusNajmabadi deleted the hasAnnotations branch February 15, 2024 22:36
@ghost ghost added this to the Next milestone Feb 15, 2024
@jjonescz jjonescz modified the milestones: Next, 17.10 P2 Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers 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.

5 participants