未验证 提交 4e102e1f 编写于 作者: S Sam Harwell 提交者: GitHub

Merge pull request #45477 from sharwell/touch-document-lite

Reduce memory required for document change processing queues
......@@ -94,10 +94,7 @@ private void OnWorkspaceChanged(object sender, WorkspaceChangeEventArgs e)
var oldDocument = e.OldSolution.GetDocument(e.DocumentId);
var newDocument = e.NewSolution.GetDocument(e.DocumentId);
// make sure we do this in background thread. we don't care about ordering of events
// we just need to refresh OB at some point if it ever needs to be updated
// link to the bug tracking root cause - https://devdiv.visualstudio.com/DefaultCollection/DevDiv/_workitems?id=169649&_a=edit
Task.Run(() => DocumentChangedAsync(oldDocument, newDocument));
UpdateDocument(oldDocument, newDocument);
break;
case WorkspaceChangeKind.ProjectAdded:
......@@ -117,17 +114,21 @@ private void OnWorkspaceChanged(object sender, WorkspaceChangeEventArgs e)
}
}
private async Task DocumentChangedAsync(Document oldDocument, Document newDocument)
private void UpdateDocument(Document oldDocument, Document newDocument)
{
try
{
var oldTextVersion = await oldDocument.GetTextVersionAsync(CancellationToken.None).ConfigureAwait(false);
var newTextVersion = await newDocument.GetTextVersionAsync(CancellationToken.None).ConfigureAwait(false);
if (oldTextVersion != newTextVersion)
// If the versions are the same, avoid updating the object browser. However, avoid
// loading the document to determine the version because it can cause extreme memory
// pressure during batch changes.
if (oldDocument.TryGetTextVersion(out var oldTextVersion)
&& newDocument.TryGetTextVersion(out var newTextVersion)
&& oldTextVersion == newTextVersion)
{
UpdateClassAndMemberVersions();
return;
}
UpdateClassAndMemberVersions();
}
catch (Exception e) when (FatalError.Report(e))
{
......
......@@ -67,6 +67,10 @@ public bool TryGetTextVersion(out VersionStamp version)
{
version = textAndVersion.Version;
}
else if (_initialSource is ITextVersionable textVersionable)
{
return textVersionable.TryGetTextVersion(out version);
}
}
return version != default;
......
......@@ -97,7 +97,19 @@ protected static ValueSource<TextAndVersion> CreateStrongText(TextLoader loader,
}
protected static ValueSource<TextAndVersion> CreateRecoverableText(TextAndVersion text, SolutionServices services)
=> new RecoverableTextAndVersion(CreateStrongText(text), services.TemporaryStorage);
{
var result = new RecoverableTextAndVersion(CreateStrongText(text), services.TemporaryStorage);
// This RecoverableTextAndVersion is created directly from a TextAndVersion instance. In its initial state,
// the RecoverableTextAndVersion keeps a strong reference to the initial TextAndVersion, and only
// transitions to a weak reference backed by temporary storage after the first time GetValue (or
// GetValueAsync) is called. Since we know we are creating a RecoverableTextAndVersion for the purpose of
// avoiding problematic address space overhead, we call GetValue immediately to force the object to weakly
// hold its data from the start.
result.GetValue();
return result;
}
protected static ValueSource<TextAndVersion> CreateRecoverableText(TextLoader loader, DocumentId documentId, SolutionServices services)
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册