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

Remove solution replicatoin context #73117

Merged
merged 6 commits into from
Apr 20, 2024

Conversation

CyrusNajmabadi
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi commented Apr 20, 2024

I'm virtually certain this type serves no purpose. I think the original intent was to root objects in memory so that they wouldn't get cleaned up, causing their underlying memory to go away, while we were in the process of communicating with our oop process.

However, what has become clearer over investigation, and several refactorings, is that our snapshots basically do not get dropped (they are dumped into memory mapped files that stay around). As such, needing to root anything isn't necessary.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 20, 2024
{
cancellationToken.ThrowIfCancellationRequested();
if (_storage is not null)
{
context.AddResource(_storage);
Copy link
Member Author

Choose a reason for hiding this comment

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

the underlying _storage instance for a SerializableSourceText is never disposed. So there's no way for hte memory it points to to go away. So there's no need to root it in this context object.

@@ -331,8 +329,6 @@ private static void WriteTo(Metadata? metadata, ObjectWriter writer, Cancellatio
return false;
}

context.AddResource(storage);
Copy link
Member Author

Choose a reason for hiding this comment

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

this is a similar issue. walking through all the ITempStorage code, none of the types that we are serializing here which dump themselves into temp-storage ever get disposed. so there's no need to keep this alive either.

// PinnedObject will be kept alive as long as the ModuleMetadata is alive due to passing its .Dispose method in
// as the onDispose callback of the metadata.
return ModuleMetadata.CreateFromMetadata(
pinnedObject.GetPointer(), (int)length, pinnedObject.Dispose);
}

private static void CopyByteArrayToStream(ObjectReader reader, Stream stream, CancellationToken cancellationToken)
Copy link
Member Author

Choose a reason for hiding this comment

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

Note: look into the deleted SolutionReplicationContext file below.

// Currently we don't dispose resources, only keep them alive.
// Shouldn't we dispose them?
// _resources.All(resource => resource.Dispose());
s_pool.ClearAndFree(_resources);
Copy link
Member Author

Choose a reason for hiding this comment

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

note how we never dispose tehse objects. Nor should we. When serializing out to oop, just because something was written out to a MMF does not mean we should dispose that mmf, it's an entirely orthogonal concern outside of the scope of a remote call to oop.

The only value this type produced was to root those disposables, presumably to ensure that anything they were holding onto didn't go away over the lifetime of hte call. However, none of that is necessary. Either we're literally serializing out a value by-value over the wire. In which case we don't need to keep it alive. Or we're serializing it out by-reference (e.g. serializing out it's location in an MMF). But in all those cases, the mmfs are never released anyways, so there's no need to keep anything alive.

@CyrusNajmabadi CyrusNajmabadi marked this pull request as ready for review April 20, 2024 04:11
@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner April 20, 2024 04:11
@CyrusNajmabadi
Copy link
Member Author

@ToddGrun this is ready for review. I've now audited everything in the MMF codebase. And we definitely do not ever release the data. so all the work to try to keep objects rooted is just unnecessary and can be removed.

@ToddGrun
Copy link
Contributor

OK, I think this looks good, the explanations definitely helped.


In reply to: 2067542936

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:

@CyrusNajmabadi CyrusNajmabadi merged commit e73a87a into dotnet:main Apr 20, 2024
25 checks passed
@CyrusNajmabadi CyrusNajmabadi deleted the removeDisposable branch April 20, 2024 06:01
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Apr 20, 2024
CyrusNajmabadi added a commit to CyrusNajmabadi/roslyn that referenced this pull request Apr 20, 2024
…posable"

This reverts commit e73a87a, reversing
changes made to 2c0668d.
@CyrusNajmabadi
Copy link
Member Author

@jasonmalinowski For review when you get back.

@dibarbet dibarbet modified the milestones: Next, 17.11 P1 Apr 29, 2024
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

3 participants