Skip to content

Don't hold onto some SourceTexts if multiple changes happen#53579

Merged
jasonmalinowski merged 2 commits intodotnet:release/dev16.11from
jasonmalinowski:consolidate-in-progress-compilation-steps
May 25, 2021
Merged

Don't hold onto some SourceTexts if multiple changes happen#53579
jasonmalinowski merged 2 commits intodotnet:release/dev16.11from
jasonmalinowski:consolidate-in-progress-compilation-steps

Conversation

@jasonmalinowski
Copy link
Member

If we are processing edits through TryApplyChanges for closed files, we'll make a series of changes in rapid succession: we'll have one change that may open the file in an invisible editor, then we'll edit the file, and then close again. The Solution object would then be holding onto the old Compilation with several changes queued, which would root the intermediate states that still pointed the editor contents and their change lists which can be large. Once a Compilation was requested for this new file, we'd process all the changes and free the memory, but if the file is closed we might not get to that right away.

@jasonmalinowski jasonmalinowski self-assigned this May 21, 2021
@ghost ghost added the Area-IDE label May 21, 2021
@jasonmalinowski jasonmalinowski marked this pull request as ready for review May 21, 2021 19:23
@jasonmalinowski jasonmalinowski requested review from a team as code owners May 21, 2021 19:23
Copy link
Contributor

Choose a reason for hiding this comment

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

💭 Is it possible to end up in a state where two TouchDocumentAction instances are separated by something else? In such a case, is it sufficient to simply ignore all but the last TouchDocumentAction?

Copy link
Member Author

Choose a reason for hiding this comment

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

@sharwell: good question! Yep, this could be made smarter. A case where you have a Solution snapshot, and keep forking it with alternate edits to A.cs and B.cs won't consolidate those together with this, even though the earlier replacements don't really matter. There's some icky edge cases though more generally with how the code works. Consider a case where the user does the following changes, forking a Solution each time.

  1. Replaces the contents of A.cs.
  2. Removes A.cs.
  3. Adds A.cs back with the same document ID.
  4. Replaces the contents of A.cs again.

(Is this sense of operations sensical? No. Which probably means there's code out there that does it. 😄 )

Clearly the change in step 1 doesn't matter, however when we run the translation action for the second step, it's implemented as "remove the syntax tree that should be there for A.cs", but if step 1 doesn't run, it'd be the wrong tree. A smarter algorithm would probably be "we can merge any two TouchDocumentActions as long as we don't move them across any other action", but I'd want to see a case where that mattered before we wrote the fancier code and tests.

@jasonmalinowski
Copy link
Member Author

@jinujoseph for 16.11 approval; this is fixing a memory usage issue which a customer is hitting for their extension. Change is small enough and is pretty targeted so not to worrisome on the risk side of things.

If we are processing edits through TryApplyChanges for closed files,
we'll make a series of changes in rapid succession: we'll have one
change that may open the file in an invisible editor, then we'll
edit the file, and then close again. The Solution object would then
be holding onto the old Compilation with several changes queued, which
would root the intermediate states that still pointed the editor
contents and their change lists which can be large. Once a Compilation
was requested for this new file, we'd process all the changes and
free the memory, but if the file is closed we might not get to that
right away.
@jasonmalinowski jasonmalinowski force-pushed the consolidate-in-progress-compilation-steps branch from e3dc96d to 5cc6571 Compare May 25, 2021 15:25
@jasonmalinowski jasonmalinowski enabled auto-merge May 25, 2021 15:26
@jasonmalinowski jasonmalinowski merged commit 359a442 into dotnet:release/dev16.11 May 25, 2021
@jasonmalinowski jasonmalinowski deleted the consolidate-in-progress-compilation-steps branch May 25, 2021 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants