Skip to content

Cleanup the code we have to run copilot code in parallel #78324

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

CyrusNajmabadi
Copy link
Member

No description provided.

@CyrusNajmabadi CyrusNajmabadi requested a review from genlu April 25, 2025 19:01
@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner April 25, 2025 19:01
@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 25, 2025
{
// Exposed for testing
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: i couldn't find this actually read anywhere. if it is used for testing, it should be exposed through a GetTestAccessor() method.

@@ -30,10 +30,6 @@
<ProjectReference Include="..\..\Core\Portable\Microsoft.CodeAnalysis.Features.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Threading" />
</ItemGroup>
Copy link
Member Author

Choose a reason for hiding this comment

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

definitely do not want this.

builder.Add(item);
}

return builder.ToArray();
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 really should be using an IProgress value in LSP. That way this can stream the context items back to the caller, and so we can be canceled if we take too long, while also providing some items back that can be used within the time budgets of hte caller.

Copy link
Member

Choose a reason for hiding this comment

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

yea, I was planning to do this, just didn'r have time to figure out how to return an AyncIterable yet
see: https://github.com/github/copilot-client/blob/fa8dce2647472b64bbad2128acb607d11811ead8/types/src/contextProviderApiV1.ts#L55

private readonly ImmutableArray<IContextProvider> _providers = [.. providers];

public IAsyncEnumerable<IContextItem> GetContextItemsAsync(Document document, int position, IReadOnlyDictionary<string, object> activeExperiments, CancellationToken cancellationToken)
=> ProducerConsumer<IContextItem>.RunParallelStreamAsync(
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 automatically parallelizes, prefering to utilize all cores to finish a fixed set of work that is then added to as work items complete. this is better than kicking off N items (which may be far mroe than the number of cores), causing them to contend with each other, and trying to .WhenAll them.

callback(item);

return default;
}, 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.

note: if ProvideContextItemsAsync just took an Action this could would be simplified to:

Suggested change
}, cancellationToken).ConfigureAwait(false),
(provider, cancellationToken) => provider.ProvideContextItemsAsync(
document, position, activeExperiments, callback, cancellationToken);

Which is much nicer and cleaner. It's unclear why we're passing a callback that has to package up everything in an array and be async.

@CyrusNajmabadi
Copy link
Member Author

@genlu ptal.

Note: i would like to take this, and include inthe backport if possible.

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 VSCode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants