-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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 LOH allocs when applying code fixes. #73424
Conversation
@@ -16,7 +16,7 @@ internal abstract class AbstractLinkedFileMergeConflictCommentAdditionService : | |||
{ | |||
internal abstract string GetConflictCommentText(string header, string beforeString, string afterString); | |||
|
|||
public IEnumerable<TextChange> CreateEdits(SourceText originalSourceText, IEnumerable<UnmergedDocumentChanges> unmergedChanges) | |||
public List<TextChange> CreateEdits(SourceText originalSourceText, List<UnmergedDocumentChanges> unmergedChanges) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed a lot of the APIs to not be IEnumerable-bases (as it's impossible to tell what is lazy and waht isn't). this also means things like enumerations don't allocate.
var textchanges = await textDiffService.GetTextChangesAsync(oldDocument, newDocument, cancellationToken).ConfigureAwait(false); | ||
foreach (var change in textchanges) | ||
var textChanges = await textDiffService.GetTextChangesAsync( | ||
oldDocument, newDocument, TextDifferenceTypes.Line, cancellationToken).ConfigureAwait(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
switching to Line-based-diff is a major win here. We normally do word-based, which leads to massive allocations in hte VS side (they're the impl of this service).
@ToddGrun ptal. |
@@ -9,9 +9,9 @@ | |||
|
|||
namespace Microsoft.CodeAnalysis; | |||
|
|||
internal sealed class UnmergedDocumentChanges(IEnumerable<TextChange> unmergedChanges, string projectName, DocumentId documentId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oldDocument.Project.Name, | ||
oldDocument.Id)); | ||
} | ||
|
||
return successfullyMergedChanges.ToImmutableAndFree(); | ||
return successfullyMergedChanges.ToImmutable(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/Workspaces/Core/Portable/LinkedFileDiffMerging/LinkedFileDiffMergingSession.cs
Outdated
Show resolved
Hide resolved
…iffMergingSession.cs
@@ -309,7 +309,7 @@ public void LogLinkedFileResult(LinkedFileGroupSessionInfo info) | |||
=> LinkedFileGroups.Add(info); | |||
} | |||
|
|||
internal class LinkedFileGroupSessionInfo | |||
internal sealed class LinkedFileGroupSessionInfo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drops LOH allocs from 1.1GB:
to around 50mb: