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

Improve incremental handling in regex generator #83868

Merged
merged 2 commits into from
Mar 24, 2023

Conversation

stephentoub
Copy link
Member

I noticed that the regex generator wasn't being as incremental as was intended. One issue that had previously been pointed out was that the data returned from the initial pipeline stage included a SyntaxNode, which caused comparison of the cached result against a new compilation to fail. Another issue @chsienki found was that the initial stage was doing the regex parsing and including the parsed regex tree in the result, but that doesn't define anything other than reference equality, so it was also prohibiting reuse of the cached result. On top of that, even if the caching worked, the regex parsing and analysis is relatively expensive, and it would end up being done on every recompilation regardless of whether the result could be cached.

Chris fixed the location issue by creating a new Location with the relevant file path/span from the original but without referencing the syntax tree. And he fixed the parsing by moving that logic out into a subsequent stage.

We also cleaned up the parsing routine, which no longer needed to find the GeneratedRegexAttribute on its own, as it's now handed into the method in the context supplied by ForAttributeWithMetadataName.

chsienki and others added 2 commits March 23, 2023 20:13
- Don't calculate the tree or analysis inside the semantic info.
- Dont' store methodDeclartionSyntax and store a comparable across runs location instead.
@ghost
Copy link

ghost commented Mar 24, 2023

Tagging subscribers to this area: @dotnet/area-system-text-regularexpressions
See info in area-owners.md if you want to be subscribed.

Issue Details

I noticed that the regex generator wasn't being as incremental as was intended. One issue that had previously been pointed out was that the data returned from the initial pipeline stage included a SyntaxNode, which caused comparison of the cached result against a new compilation to fail. Another issue @chsienki found was that the initial stage was doing the regex parsing and including the parsed regex tree in the result, but that doesn't define anything other than reference equality, so it was also prohibiting reuse of the cached result. On top of that, even if the caching worked, the regex parsing and analysis is relatively expensive, and it would end up being done on every recompilation regardless of whether the result could be cached.

Chris fixed the location issue by creating a new Location with the relevant file path/span from the original but without referencing the syntax tree. And he fixed the parsing by moving that logic out into a subsequent stage.

We also cleaned up the parsing routine, which no longer needed to find the GeneratedRegexAttribute on its own, as it's now handed into the method in the context supplied by ForAttributeWithMetadataName.

Author: stephentoub
Assignees: -
Labels:

area-System.Text.RegularExpressions

Milestone: -

@stephentoub stephentoub merged commit 8a7a91c into dotnet:main Mar 24, 2023
@stephentoub stephentoub deleted the fixincrementalregexsg branch March 24, 2023 21:05
@ghost ghost locked as resolved and limited conversation to collaborators Apr 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants