Skip to content

Conversation

@davidwengier
Copy link
Member

Fixes #6756
Fixes #8176

The compiler team fixed the perf of GetContent() in #8032 but we were still being pretty naive in our usage here, and the use of Environment.NewLine was just wrong.

Results show no harm without a large comment, but a big saving in allocations when there is a large comment.

Old:

Method WithMultiLineComment Mean Error StdDev Median Min Max Gen0 Gen1 Allocated
RazorSemanticTokensRangeAsync False 53.43 us 1.057 us 2.428 us 53.54 us 48.58 us 60.56 us 0.6104 - 3.75 KB
RazorSemanticTokensRangeAsync True 97.77 us 1.787 us 1.912 us 98.18 us 93.45 us 100.36 us 6.1035 0.2441 34.87 KB

New:

Method WithMultiLineComment Mean Error StdDev Median Min Max Gen0 Gen1 Allocated
RazorSemanticTokensRangeAsync False 53.50 us 1.023 us 1.218 us 53.63 us 50.81 us 55.36 us 0.6104 0.0610 3.75 KB
RazorSemanticTokensRangeAsync True 83.66 us 1.581 us 1.401 us 83.25 us 82.27 us 86.72 us 2.6855 0.1221 15.29 KB

@davidwengier davidwengier requested a review from a team as a code owner June 14, 2023 01:45
1 0 19 razorComment 0
1 0 3 razorComment 0
0 3 1 razorCommentStar 0
0 1 1 razorCommentTransition 0
Copy link
Member Author

Choose a reason for hiding this comment

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

Importantly, with the previous code, this test snapshot file and the above test snapshot file were different, which is the bug this is fixing. All other test snapshots are unchanged because the rest is just perf work.

@davidwengier davidwengier changed the title Expand benchmark to include document with a large comment Fix perf of multiline semantic tokens, and LF handling of same Jun 14, 2023
// Blank line. The less than check is important because we could have seen two newline characters, but
// be in a situation where we have an LF file with multiple blank lines, so endChar would be -1. Still
// a blank line though :)
if (endChar <= 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

❓ would it make more sense to have GetLastNonWhitespaceCharacterOffset not return a negative number? Will comment below on proposed change

Copy link
Member Author

Choose a reason for hiding this comment

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

Good call, thank you! Couldn't see the forrest for the trees :)

lineLength--;

var lineEndAbsoluteIndex = lineStartAbsoluteIndex + lineLength;
if (lineEndAbsoluteIndex == 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (lineEndAbsoluteIndex == 0)
if (lineEndAbsoluteIndex == 0 || lineLength == 0)

@davidwengier davidwengier merged commit 33fceb7 into dotnet:main Jun 16, 2023
@davidwengier davidwengier deleted the DontCallGetContent branch June 16, 2023 06:27
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.

Razor syntax highlighting fails for multi-line comments and LF endings Potential perf issue with semantic classification

3 participants