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 LOH allocs when applying code fixes. #73424

Merged
merged 24 commits into from May 13, 2024

Conversation

CyrusNajmabadi
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi commented May 10, 2024

Drops LOH allocs from 1.1GB:

image

to around 50mb:

image

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels May 10, 2024
@CyrusNajmabadi CyrusNajmabadi changed the title WIP. Reduce LOH allocs when applying code fixes. May 10, 2024
@CyrusNajmabadi CyrusNajmabadi marked this pull request as ready for review May 10, 2024 17:15
@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner May 10, 2024 17:15
@@ -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)
Copy link
Member Author

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);
Copy link
Member Author

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).

@CyrusNajmabadi
Copy link
Member Author

@ToddGrun ptal.

@@ -9,9 +9,9 @@

namespace Microsoft.CodeAnalysis;

internal sealed class UnmergedDocumentChanges(IEnumerable<TextChange> unmergedChanges, string projectName, DocumentId documentId)
Copy link
Contributor

Choose a reason for hiding this comment

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

internal

might as well clear out the #nullable in this file too

oldDocument.Project.Name,
oldDocument.Id));
}

return successfullyMergedChanges.ToImmutableAndFree();
return successfullyMergedChanges.ToImmutable();
Copy link
Contributor

Choose a reason for hiding this comment

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

ToImmutable

Haven't you been primarily using ToImmutableAndClear in these situations?

@@ -309,7 +309,7 @@ public void LogLinkedFileResult(LinkedFileGroupSessionInfo info)
=> LinkedFileGroups.Add(info);
}

internal class LinkedFileGroupSessionInfo
internal sealed class LinkedFileGroupSessionInfo
Copy link
Contributor

Choose a reason for hiding this comment

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

sealed

seal the class right above this too?

Copy link
Contributor

@ToddGrun ToddGrun left a comment

Choose a reason for hiding this comment

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

:shipit:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE 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.

None yet

2 participants