-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Provide a ProducerConsumer helper for processing a sequence of items in parallel. #73323
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a83b76d
Add helper
CyrusNajmabadi a634cde
move over to helper
CyrusNajmabadi c1fcda1
move over to helper
CyrusNajmabadi 61189c9
Merge branch 'producerConsumer' into parallelHelper
CyrusNajmabadi 6aeef66
move over to helper
CyrusNajmabadi b97aa92
Merge branch 'producerConsumerRefactoring' into parallelHelper
CyrusNajmabadi df389cc
Merge branch 'producerConsumerRefactoring' into parallelHelper
CyrusNajmabadi b469572
cleanup
CyrusNajmabadi 2ef48d8
Merge branch 'main' into parallelHelper
CyrusNajmabadi 3e0d17d
Named arg
CyrusNajmabadi 63a8296
Simplify
CyrusNajmabadi 4f00d52
cnacellation
CyrusNajmabadi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,45 +121,41 @@ public async Task<ImmutableArray<CodeRefactoring>> GetRefactoringsAsync( | |
foreach (var provider in orderedProviders) | ||
providerToIndex.Add(provider, providerToIndex.Count); | ||
|
||
await ProducerConsumer<(CodeRefactoringProvider provider, CodeRefactoring codeRefactoring)>.RunAsync( | ||
ProducerConsumerOptions.SingleReaderOptions, | ||
produceItems: static (callback, args) => | ||
await ProducerConsumer<(CodeRefactoringProvider provider, CodeRefactoring codeRefactoring)>.RunParallelAsync( | ||
source: orderedProviders, | ||
produceItems: static async (provider, callback, args, cancellationToken) => | ||
{ | ||
// Run all providers in parallel to get the set of refactorings for this document. | ||
RoslynParallel.ForEachAsync( | ||
args.orderedProviders, | ||
args.cancellationToken, | ||
async (provider, cancellationToken) => | ||
{ | ||
// Log an individual telemetry event for slow code refactoring computations to | ||
// allow targeted trace notifications for further investigation. 500 ms seemed like | ||
// a good value so as to not be too noisy, but if fired, indicates a potential | ||
// area requiring investigation. | ||
const int CodeRefactoringTelemetryDelay = 500; | ||
|
||
var providerName = provider.GetType().Name; | ||
|
||
var logMessage = KeyValueLogMessage.Create(m => | ||
{ | ||
m[TelemetryLogging.KeyName] = providerName; | ||
m[TelemetryLogging.KeyLanguageName] = args.document.Project.Language; | ||
}); | ||
|
||
using (args.addOperationScope(providerName)) | ||
using (RoslynEventSource.LogInformationalBlock(FunctionId.Refactoring_CodeRefactoringService_GetRefactoringsAsync, providerName, cancellationToken)) | ||
using (TelemetryLogging.LogBlockTime(FunctionId.CodeRefactoring_Delay, logMessage, CodeRefactoringTelemetryDelay)) | ||
{ | ||
var refactoring = await [email protected]( | ||
args.document, args.state, provider, args.options, cancellationToken).ConfigureAwait(false); | ||
if (refactoring != null) | ||
callback((provider, refactoring)); | ||
} | ||
}), | ||
consumeItems: static async (reader, args) => | ||
// Log an individual telemetry event for slow code refactoring computations to | ||
// allow targeted trace notifications for further investigation. 500 ms seemed like | ||
// a good value so as to not be too noisy, but if fired, indicates a potential | ||
// area requiring investigation. | ||
const int CodeRefactoringTelemetryDelay = 500; | ||
|
||
var providerName = provider.GetType().Name; | ||
|
||
var logMessage = KeyValueLogMessage.Create(m => | ||
{ | ||
m[TelemetryLogging.KeyName] = providerName; | ||
m[TelemetryLogging.KeyLanguageName] = args.document.Project.Language; | ||
}); | ||
|
||
using (args.addOperationScope(providerName)) | ||
using (RoslynEventSource.LogInformationalBlock(FunctionId.Refactoring_CodeRefactoringService_GetRefactoringsAsync, providerName, cancellationToken)) | ||
using (TelemetryLogging.LogBlockTime(FunctionId.CodeRefactoring_Delay, logMessage, CodeRefactoringTelemetryDelay)) | ||
{ | ||
var refactoring = await [email protected]( | ||
args.document, args.state, provider, args.options, cancellationToken).ConfigureAwait(false); | ||
if (refactoring != null) | ||
callback((provider, refactoring)); | ||
} | ||
}, | ||
consumeItems: static async (reader, args, cancellationToken) => | ||
{ | ||
await foreach (var pair in reader) | ||
args.pairs.Add(pair); | ||
}, | ||
args: (@this: this, document, state, orderedProviders, options, addOperationScope, pairs, cancellationToken), | ||
args: (@this: this, document, state, options, addOperationScope, pairs), | ||
cancellationToken).ConfigureAwait(false); | ||
|
||
return pairs | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,13 +90,13 @@ private static IEnumerable<T> Prioritize<T>(IEnumerable<T> items, Func<T, bool> | |
/// </summary> | ||
private static Task PerformParallelSearchAsync<T>( | ||
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. I can consider removing in follow up |
||
IEnumerable<T> items, | ||
Func<T, Action<RoslynNavigateToItem>, ValueTask> callback, | ||
Func<T, Action<RoslynNavigateToItem>, CancellationToken, ValueTask> callback, | ||
Func<ImmutableArray<RoslynNavigateToItem>, Task> onItemsFound, | ||
CancellationToken cancellationToken) | ||
=> ProducerConsumer<RoslynNavigateToItem>.RunAsync( | ||
ProducerConsumerOptions.SingleReaderOptions, | ||
produceItems: static (onItemFound, args) => RoslynParallel.ForEachAsync(args.items, args.cancellationToken, (item, cancellationToken) => args.callback(item, onItemFound)), | ||
consumeItems: static (items, args) => args.onItemsFound(items), | ||
args: (items, callback, onItemsFound, cancellationToken), | ||
=> ProducerConsumer<RoslynNavigateToItem>.RunParallelAsync( | ||
source: items, | ||
produceItems: static async (item, onItemFound, args, cancellationToken) => await args.callback(item, onItemFound, cancellationToken).ConfigureAwait(false), | ||
consumeItems: static (items, args, cancellationToken) => args.onItemsFound(items), | ||
args: (items, callback, onItemsFound), | ||
cancellationToken); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,9 +81,9 @@ public async Task FindReferencesAsync( | |
{ | ||
await ProducerConsumer<Reference>.RunAsync( | ||
ProducerConsumerOptions.SingleReaderOptions, | ||
produceItems: static (onItemFound, args) => [email protected](args.symbols, onItemFound, args.cancellationToken), | ||
consumeItems: static async (references, args) => await args.@this._progress.OnReferencesFoundAsync(references, @args.cancellationToken).ConfigureAwait(false), | ||
(@this: this, symbols, cancellationToken), | ||
produceItems: static (onItemFound, args, cancellationToken) => [email protected](args.symbols, onItemFound, cancellationToken), | ||
consumeItems: static async (references, args, cancellationToken) => await args.@this._progress.OnReferencesFoundAsync(references, cancellationToken).ConfigureAwait(false), | ||
(@this: this, symbols), | ||
cancellationToken).ConfigureAwait(false); | ||
} | ||
finally | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
view with whitespace off.