Skip to content

NES xtab: gather language context and neighbor snippets concurrently instead of sequentially #324039

Description

@ulugbekna

In XtabProvider.provideNextEdit (extensions/copilot/src/extension/xtab/node/xtabProvider.ts), the two context-gathering steps are awaited one after the other:

langCtx = await gatherLanguageContext();
if (cancellationToken.isCancellationRequested) { return new NoNextEditReason.GotCancelled('afterLanguageContextAwait'); }

neighborSnippets = await gatherNeighborSnippets();
if (cancellationToken.isCancellationRequested) { return new NoNextEditReason.GotCancelled('afterNeighborSnippetsAwait'); }

gatherLanguageContext() and gatherNeighborSnippets() are independent, so awaiting them sequentially adds their latencies together on the critical path before the prompt can be built. They should be started together (e.g. Promise.all) so they run concurrently.

Notes for whoever picks this up:

  • This pattern appears in both the global-budget branch and the legacy/prod else branch, so both should be updated.
  • Preserve the existing cancellation checks and their distinct GotCancelled reasons (afterLanguageContextAwait, afterNeighborSnippetsAwait) for telemetry continuity, checking cancellation after the combined await.
  • Preserve the nLinesOfCurrentFileInPrompt telemetry timing in the prod branch (the current-file clip happens before these awaits there).

Surfaced during review of #323948.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions