Skip to content

Get rid of LineTrackingStringBuffer class and instead use the line in… #22903

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

Merged
merged 3 commits into from
Jun 15, 2020

Conversation

ToddGrun
Copy link
Contributor

…formation provided by RazorSourceDocument.

This additionally gets rid of an extra whole buffer allocation in the ParserContext. The most complex bit of the change is around avoiding TextLineCollection.GetLocation.

Overall, I'm seeing a pretty big win here, about 35% less time spent in RazorSyntaxTree.Parse for the typing scenario I was doing in a very large file.

…formation provided by RazorSourceDocument.

This additionally gets rid of an extra whole buffer allocation in the ParserContext. The most complex bit of the change is around avoiding TextLineCollection.GetLocation.

Overall, I'm seeing a pretty big win here, about 35% less time spent in RazorSyntaxTree.Parse for the typing scenario I was doing in a very large file.
@ghost ghost added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Jun 13, 2020
break;

Choose a reason for hiding this comment

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

👏

{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}

_buffer = new LineTrackingStringBuffer(source, filePath);
_sourceDocument = source;
_cachedLineInfo = (new TextSpan(0, _sourceDocument.Lines.GetLineLength(0)), 0);

Choose a reason for hiding this comment

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

This is confusing to me. Why cache the very first line and special case that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It simplified the code so it didnt need to check against uninitialized. Also, callers tend to start at the first line.

Copy link
Contributor

Choose a reason for hiding this comment

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

This assumes that RazorSourceDocument will have atleast one line right? Is it safe to make that assumption?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On empty documents, _sourceDocument.Lines.Count == 1. See


In reply to: 440388134 [](ancestors = 440388134)


public SeekableTextReader(string source, string filePath) : this(source.ToCharArray(), filePath) { }
public SeekableTextReader(string source, string filePath) : this(new StringSourceDocument(source, Encoding.UTF8, new RazorSourceDocumentProperties(filePath, relativePath: null))) { }
Copy link
Contributor

Choose a reason for hiding this comment

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

Where is this constructor currently being used?

Copy link
Contributor Author

@ToddGrun ToddGrun Jun 15, 2020

Choose a reason for hiding this comment

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

Two places from test code and once from LanguageCharacteristics.TokenizeString which is called from several places in product code. Perhaps UTF8 isn't appropriate here, maybe Encoding.Unicode?


In reply to: 440378902 [](ancestors = 440378902)

Copy link
Contributor

Choose a reason for hiding this comment

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

Spoke offline. UTF8 is fine as we do the same thing in most other places as well.

{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}

_buffer = new LineTrackingStringBuffer(source, filePath);
_sourceDocument = source;
_cachedLineInfo = (new TextSpan(0, _sourceDocument.Lines.GetLineLength(0)), 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

This assumes that RazorSourceDocument will have atleast one line right? Is it safe to make that assumption?

if (_position >= _cachedLineInfo.Span.End)
{
// Try to avoid the GetLocation call by checking if the next line contains the position
int nextLineIndex = _cachedLineInfo.LineIndex + 1;
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
int nextLineIndex = _cachedLineInfo.LineIndex + 1;
var nextLineIndex = _cachedLineInfo.LineIndex + 1;

Similarly in other places as well

@ToddGrun ToddGrun merged commit ef0eff7 into master Jun 15, 2020
@ToddGrun ToddGrun deleted the dev/toddgrun/NoMoreLineTrackingStringBuffer branch June 15, 2020 21:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants