-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Switch to a callback style in the asset finding code #73017
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,14 +58,17 @@ public async Task AddAssetsAsync( | |
var numberOfChecksumsToSearch = checksumsToFind.Count; | ||
Contract.ThrowIfTrue(checksumsToFind.Contains(Checksum.Null)); | ||
|
||
await FindAssetsAsync(assetPath, checksumsToFind, assetMap, cancellationToken).ConfigureAwait(false); | ||
await FindAssetsAsync( | ||
assetPath, checksumsToFind, | ||
(checksum, asset) => assetMap[checksum] = asset, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Containing PR gets rid of the closure allocation (or will once #73013 (comment) is addressed) |
||
cancellationToken).ConfigureAwait(false); | ||
|
||
Contract.ThrowIfTrue(checksumsToFind.Count > 0); | ||
Contract.ThrowIfTrue(assetMap.Count != numberOfChecksumsToSearch); | ||
} | ||
|
||
private async Task FindAssetsAsync( | ||
AssetPath assetPath, HashSet<Checksum> remainingChecksumsToFind, Dictionary<Checksum, object> result, CancellationToken cancellationToken) | ||
AssetPath assetPath, HashSet<Checksum> remainingChecksumsToFind, Action<Checksum, object> onAssetFound, CancellationToken cancellationToken) | ||
{ | ||
var solutionState = this.CompilationState; | ||
|
||
|
@@ -74,13 +77,13 @@ private async Task FindAssetsAsync( | |
// If we're not in a project cone, start the search at the top most state-checksum corresponding to the | ||
// entire solution. | ||
Contract.ThrowIfFalse(solutionState.TryGetStateChecksums(out var stateChecksums)); | ||
await stateChecksums.FindAsync(solutionState, this.ProjectCone, assetPath, remainingChecksumsToFind, result, cancellationToken).ConfigureAwait(false); | ||
await stateChecksums.FindAsync(solutionState, this.ProjectCone, assetPath, remainingChecksumsToFind, onAssetFound, cancellationToken).ConfigureAwait(false); | ||
} | ||
else | ||
{ | ||
// Otherwise, grab the top-most state checksum for this cone and search within that. | ||
Contract.ThrowIfFalse(solutionState.TryGetStateChecksums(this.ProjectCone.RootProjectId, out var stateChecksums)); | ||
await stateChecksums.FindAsync(solutionState, this.ProjectCone, assetPath, remainingChecksumsToFind, result, cancellationToken).ConfigureAwait(false); | ||
await stateChecksums.FindAsync(solutionState, this.ProjectCone, assetPath, remainingChecksumsToFind, onAssetFound, cancellationToken).ConfigureAwait(false); | ||
} | ||
} | ||
|
||
|
@@ -97,10 +100,10 @@ public async ValueTask<object> GetAssetAsync(Checksum checksum, CancellationToke | |
{ | ||
Contract.ThrowIfTrue(checksum == Checksum.Null); | ||
|
||
using var checksumPool = Creator.CreateChecksumSet(checksum); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
using var _ = Creator.CreateResultMap(out var resultPool); | ||
|
||
await scope.FindAssetsAsync(AssetPath.FullLookupForTesting, checksumPool.Object, resultPool, cancellationToken).ConfigureAwait(false); | ||
var checksums = new ReadOnlyMemory<Checksum>([checksum]); | ||
await scope.AddAssetsAsync(AssetPath.FullLookupForTesting, checksums, resultPool, cancellationToken).ConfigureAwait(false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a test call and was cleaner. Just goes through the to level path without having to make a set and make a lambda. |
||
Contract.ThrowIfTrue(resultPool.Count != 1); | ||
|
||
var (resultingChecksum, value) = resultPool.First(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of passing in dictionaries, we pass in callbacks to invoke when the item is found. In this Pr, this will still end up populating a dictionary. However in #73013 this changes to populating a channel that then allows another task to be reading from the channle when items are found, writing the assets out to our pipe between oop and the host.