Reduce LSP request handling allocations - #84623
Merged
Merged
Conversation
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
|
Azure Pipelines: Successfully started running 2 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
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
ProcessQueueCoreAsyncdispatch delegates per (method, language) instead of invoking viaMethodInfo.Invokefor every request. - Reuse a singleton
NonMutatingDocumentChangeTrackerinstance for non-mutating request contexts. - Avoid reassigning
CultureInfo.CurrentUICulturewhen 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
JoeRobich
reviewed
Jul 24, 2026
…ework/RequestExecutionQueue.cs Co-authored-by: Joey Robichaud <jorobich@microsoft.com>
akhera99
approved these changes
Jul 27, 2026
JoeRobich
approved these changes
Jul 27, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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:
Co-authored-by: Copilot App 223556219+Copilot@users.noreply.github.com
Microsoft Reviewers: Open in CodeFlow