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

Reduce allocations from newline information allocated by ChangedText.GetLinesCore #74728

Merged
merged 15 commits into from
Aug 22, 2024

Conversation

ToddGrun
Copy link
Contributor

Going to start this in draft mode and fire off a test insertion to verify this improves allocations as the typing scenario in speedometer scrolling test shows this as nearly 10% of allocations.

The general idea here is that ChangedText doesn't need to keep track of line information as the SourceText that it wraps has that information. The complexity that was in ChangedText around newline splitting now needs to sit in both CompositeText and SubText as they need to understand how to expose their line collections.

*** original allocations during the typing scenario in the scrolling speedometer test ***
image

…GetLinesCore.

Going to start this in draft mode and fire off a test insertion to verify this improves allocations as the typing scenario in speedometer scrolling test shows this as nearly 10% of allocations.

The general idea here is that ChangedText doesn't need to keep track of line information as the SourceText that it wraps has that information. The complexity that was in ChangedText around newline splitting now needs to sit in both CompositeText and SubText as they need to understand how to expose their line collections.
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Aug 13, 2024
@ToddGrun
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@ToddGrun
Copy link
Contributor Author

ToddGrun commented Aug 13, 2024

Insertion PRs to get perf numbers:

https://dev.azure.com/devdiv/DevDiv/_git/VS/pullrequest/571281
https://dev.azure.com/devdiv/DevDiv/_git/VS/pullrequest/571282

Results look promising:

*** from profile ***
image

*** from PIT ***
image

Due to this information, I'll go ahead and elevate out of draft status.

@ToddGrun ToddGrun marked this pull request as ready for review August 13, 2024 10:26
@ToddGrun ToddGrun requested a review from a team as a code owner August 13, 2024 10:26
@CyrusNajmabadi
Copy link
Member

ok. i'm going to hold off on reviewing for a bit. my brain is not up to this sort of math :) docs would be helpful, as well as intuitions fro what each op is doing. also happy to talk in person to get a rundown on all of this.

the savings are amazing. so def want this to move forward.

@ToddGrun
Copy link
Contributor Author

@RikkiGibson, @dotnet/roslyn-compiler for reviews

…handling in two different locations, just handle it in a single location up front.
Copy link
Contributor

@RikkiGibson RikkiGibson left a comment

Choose a reason for hiding this comment

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

Mostly things LGTM but need a little more time or maybe offline discussion to fully understand and sign-off.

src/Compilers/Core/Portable/Text/CompositeText.cs Outdated Show resolved Hide resolved
src/Compilers/Core/Portable/Text/CompositeText.cs Outdated Show resolved Hide resolved
src/Compilers/Core/Portable/Text/SubText.cs Show resolved Hide resolved

var underlyingTextLine = _subText.UnderlyingText.Lines[lineNumber + _startLineNumber];

var startInUnderlyingText = Math.Max(underlyingTextLine.Start, _subText.UnderlyingSpan.Start);
Copy link
Contributor

Choose a reason for hiding this comment

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

The table itself makes sense to me, but I don't understand the meaning/purpose of startInUnderlyingText. Will revisit on Monday and complete review. Thanks!

@ToddGrun
Copy link
Contributor Author

@dotnet/roslyn-compiler for 2nd review

1 similar comment
@ToddGrun
Copy link
Contributor Author

@dotnet/roslyn-compiler for 2nd review

src/Compilers/Core/Portable/Text/SubText.cs Outdated Show resolved Hide resolved
{
Debug.Assert(_subText.UnderlyingText[underlyingSpanStart - 1] == '\r' && _subText.UnderlyingText[underlyingSpanStart] == '\n');
_startsWithinSplitCRLF = true;
}
Copy link
Member

Choose a reason for hiding this comment

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

Why don't we set _startsWithinSplitCRLF when we're dealing with a zero length value? Even if it's zero length I would assume it could start and end within a CRLF

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good observation. I think this is a remnant of an earlier commit that needed this, but it doesn't look like that's the case any longer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jaredpar -- any more concerns? Should I ping compiler team again for 2nd review?

…ome data in the empty SubText.UnderlyingSpan case.
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