Skip to content

Conversation

@DustinCampbell
Copy link
Member

@DustinCampbell DustinCampbell commented Jun 6, 2025

Razor only caches a limited number of green SyntaxTokens--specifically those that have different text, such as identifiers. However, it doesn't cache green SyntaxTokens will well-known text, even though those can always be shared if they don't have any diagnostics. This PR introduces a cache for SyntaxKind to SyntaxToken to the HTML tokenizer for tokens with well-known text.

Note: This only addresses the HTML tokenizer and C# will be handled separately. Because some SyntaxKind values are shared across HTML and C# but have different text (like SyntaxKind.Equals -- "=" in HTML and "==" in C#), it'll take a more significant change to solve this in a unified way.


CI Build: https://dev.azure.com/dnceng/internal/_build/results?buildId=2724900&view=results
Toolset Run: https://dev.azure.com/dnceng/internal/_build/results?buildId=2724901&view=results

Most of the green SyntaxTokens produced by the HtmlTokenizer have well-known text and can be shared.
@DustinCampbell DustinCampbell requested a review from a team as a code owner June 6, 2025 17:43
return " ";
}
if (Buffer[0] == '\t')
switch (Buffer[0])
Copy link
Member

Choose a reason for hiding this comment

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

nit: would a switch expression (rather than statement) be more concise here?

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 considered that, but it requires adding another call to base.GetTokenContent(type) to avoid changing the current fall-through behavior. So, I opted for a regular switch to let the fall-through continue to work as it did before. So, it'd realistically only save 2 lines or so.

@DustinCampbell
Copy link
Member Author

Thanks everyone! 💖

@DustinCampbell DustinCampbell merged commit 6acba03 into dotnet:main Jun 10, 2025
11 checks passed
@DustinCampbell DustinCampbell deleted the cache-html-tokens branch June 10, 2025 15:41
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Jun 10, 2025
@RikkiGibson RikkiGibson modified the milestones: Next, 18.0 P1 Aug 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants