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

Cleanup in solution-sync code. #72990

Merged
merged 30 commits into from
Apr 12, 2024

Conversation

CyrusNajmabadi
Copy link
Member

One more pass after all the recent refactorings.

@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 12, 2024
@@ -85,7 +85,7 @@ public async Task TestAssetSynchronization()
var assetSource = new SimpleAssetSource(workspace.Services.GetService<ISerializerService>(), map);

var service = new AssetProvider(sessionId, storage, assetSource, remoteWorkspace.Services.GetService<ISerializerService>());
await service.SynchronizeAssetsAsync<object, VoidResult>(AssetPath.FullLookupForTesting, new HashSet<Checksum>(map.Keys), callback: null, arg: default, CancellationToken.None);
await service.GetAssetsAsync<object>(AssetPath.FullLookupForTesting, new HashSet<Checksum>(map.Keys), CancellationToken.None);
Copy link
Member Author

Choose a reason for hiding this comment

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

we had duplicate mehtods GetAssetsAsync and SynchronizeAssetsAsync. unified on the former name.

var projectReferences = await GetAssetsAsync<ProjectReference>(new(AssetPathKind.ProjectProjectReferences, projectId), projectChecksums.ProjectReferences, cancellationToken).ConfigureAwait(false);
var metadataReferences = await GetAssetsAsync<MetadataReference>(new(AssetPathKind.ProjectMetadataReferences, projectId), projectChecksums.MetadataReferences, cancellationToken).ConfigureAwait(false);
var analyzerReferences = await GetAssetsAsync<AnalyzerReference>(new(AssetPathKind.ProjectAnalyzerReferences, projectId), projectChecksums.AnalyzerReferences, cancellationToken).ConfigureAwait(false);
var projectReferences = await this.GetAssetsArrayAsync<ProjectReference>(new(AssetPathKind.ProjectProjectReferences, projectId), projectChecksums.ProjectReferences, 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.

for the helper that returns an array, the name 'Array' is now in the method name to indicate that's the case. the one without htat in the name is void, without allocating.


internal static class AbstractAssetProviderExtensions
{
public static Task GetAssetsAsync<TAsset>(
Copy link
Member Author

Choose a reason for hiding this comment

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

lots of hte helpers became extensions. they don't need to be in the type itself.

{
return assetProvider.GetAssetsAsync<TAsset, VoidResult>(
assetPath, checksums, callback: null, arg: default, 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.

several helpers that don't need the callbacks, but defer to the callback form

}

public static async Task GetAssetsAsync<T, TArg>(
this AbstractAssetProvider assetProvider, AssetPath assetPath, ChecksumCollection checksums, Action<Checksum, T, TArg>? callback, TArg? arg, 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.

helpers that take a ChecksumCollection instead of a HashSet<Checksum>

@@ -221,12 +210,6 @@ async ValueTask SynchronizeSolutionAssetsWorkerAsync()

return;

static void AddAll(HashSet<Checksum> checksums, ChecksumCollection checksumCollection)
Copy link
Member Author

Choose a reason for hiding this comment

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

not needed. we already have a method on ChecksumCollection for this.

@CyrusNajmabadi CyrusNajmabadi marked this pull request as ready for review April 12, 2024 00:52
@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner April 12, 2024 00:52
@CyrusNajmabadi CyrusNajmabadi requested a review from ToddGrun April 12, 2024 00:52
static AssetProvider()
{
IOUtilities.PerformIO(() => File.Delete(s_logFile));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Oops

@CyrusNajmabadi CyrusNajmabadi marked this pull request as ready for review April 12, 2024 04:13
@@ -14,7 +14,6 @@ internal enum WellKnownSynchronizationKind
// Solution snapshot state, only referencing actual user (non-generated) documents, options, and references.
SolutionState,
ProjectState,
DocumentState,
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 no longer synced to/from oop. instead, we just inline it's two checkums (attributes and text checksums) to the projectstatechecksum.

Copy link
Member Author

@CyrusNajmabadi CyrusNajmabadi Apr 12, 2024

Choose a reason for hiding this comment

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

this cuts the total number of calls form oop to the host by a third.

}

async Task SynchronizeProjectDocumentsAsync(ProjectStateChecksums projectChecksums)
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 moved to the base class. it's used in multiple places now. both when seeign that a project's documents changed, and also when doing hte initial bulk sync and makigna ProjectInfo.

@@ -52,7 +52,7 @@ static SolutionAssetCache()
/// </summary>
private readonly TimeSpan _gcAfterTimeSpan;

private readonly ConcurrentDictionary<Checksum, Entry> _assets = new(concurrencyLevel: 4, capacity: 10);
private readonly ConcurrentDictionary<Checksum, Entry> _assets = new();
Copy link
Member Author

Choose a reason for hiding this comment

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

We're on .net core. we don't want or need to artificially limit this dictionary. esp. when we want to do all this concurrent work.

@CyrusNajmabadi CyrusNajmabadi requested a review from ToddGrun April 12, 2024 04:32
projects.Add(await CreateProjectInfoAsync(projectId, projectChecksum, cancellationToken).ConfigureAwait(false));
// Fetch all the project state checksums up front. That allows gettign all the data in a single call, and
// enables parallel fetching of the projects below.
using var _1 = ArrayBuilder<ProjectStateChecksums>.GetInstance(solutionChecksums.Projects.Length, out var allProjectStateChecksums);
Copy link
Member Author

Choose a reason for hiding this comment

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

i could likely make this into the array of projectinfo tasks and populate it as we're reading back the ProjectStateChecksums.

@@ -78,3 +79,63 @@ public bool MoveNext()
=> (_checksumsAndIds.Checksums.Children[_index], _checksumsAndIds.Ids[_index]);
}
}

internal readonly struct DocumentChecksumsAndIds
Copy link
Contributor

Choose a reason for hiding this comment

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

DocumentChecksumsAndIds

Seems like this would replace ChecksumsAndIds, but it must not as that is still used in this branch.

Copy link
Contributor

@ToddGrun ToddGrun Apr 12, 2024

Choose a reason for hiding this comment

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

Maybe ChecksumsAndIdsis still just there in use cases where the caller doesn't need all the data?

@CyrusNajmabadi CyrusNajmabadi requested a review from ToddGrun April 12, 2024 17:04
@CyrusNajmabadi CyrusNajmabadi merged commit d1d11fa into dotnet:main Apr 12, 2024
27 checks passed
@CyrusNajmabadi CyrusNajmabadi deleted the syncStripesTypes branch April 12, 2024 17:50
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Apr 12, 2024
@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.

3 participants