Skip to content

Reduce LSP request handling allocations - #84623

Merged
dibarbet merged 2 commits into
dotnet:mainfrom
dibarbet:dibarbet-profile-lsp-requests
Jul 27, 2026
Merged

dibarbet merged 2 commits into
dotnet:mainfrom
dibarbet:dibarbet-profile-lsp-requests

Conversation

@dibarbet

@dibarbet dibarbet commented Jul 24, 2026

Copy link
Copy Markdown
Member

Cache typed request dispatch delegates, reuse the stateless non-mutating document tracker, and avoid redundant UI culture assignments.

Reduces per-request LSP allocations by ~300 bytes:

Per request 8,202 B 7,897 B −304 B

Co-authored-by: Copilot App 223556219+Copilot@users.noreply.github.com

Microsoft Reviewers: Open in CodeFlow

Cache typed request dispatch delegates, reuse the stateless non-mutating document tracker, and avoid redundant UI culture assignments.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 201bb75c-2f97-4655-8c19-8a08518352ac
Copilot AI review requested due to automatic review settings July 24, 2026 22:19
@dibarbet
dibarbet requested a review from a team as a code owner July 24, 2026 22:19
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR reduces per-request allocations in the Language Server Protocol (LSP) request execution pipeline by removing per-request reflection invocation overhead, reusing a stateless document-change tracker instance for non-mutating handlers, and avoiding redundant UI culture assignments.

Changes:

  • Cache typed ProcessQueueCoreAsync dispatch delegates per (method, language) instead of invoking via MethodInfo.Invoke for every request.
  • Reuse a singleton NonMutatingDocumentChangeTracker instance for non-mutating request contexts.
  • Avoid reassigning CultureInfo.CurrentUICulture when it is already set to the desired culture instance.
Show a summary per file
File Description
src/LanguageServer/Protocol/RoslynRequestExecutionQueue.cs Skips redundant CurrentUICulture assignment per request when already set to the cached culture instance.
src/LanguageServer/Protocol/Handler/RequestContext.cs Reuses NonMutatingDocumentChangeTracker.Instance instead of allocating a new tracker for each non-mutating request context.
src/LanguageServer/Protocol/Handler/IDocumentChangeTracker.cs Introduces a singleton NonMutatingDocumentChangeTracker.Instance with a private constructor to enforce reuse.
src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/RequestExecutionQueue.cs Caches typed dispatch delegates to avoid reflection-based invocation when running ProcessQueueCoreAsync for concrete request/response types.

Copilot's findings

  • Files reviewed: 4/4 changed files
  • Comments generated: 1

…ework/RequestExecutionQueue.cs

Co-authored-by: Joey Robichaud <jorobich@microsoft.com>
Copilot AI review requested due to automatic review settings July 25, 2026 00:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot's findings

  • Files reviewed: 4/4 changed files
  • Comments generated: 0 new

@dibarbet
dibarbet enabled auto-merge (squash) July 27, 2026 22:44
@dibarbet
dibarbet merged commit 30a8500 into dotnet:main Jul 27, 2026
24 of 25 checks passed
@jjonescz jjonescz added this to the 18.11 milestone Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants