Fix language server retaining pre-edit program and its checkers after program clone - #64466
Open
Nathnael Wondisha (ghost2023) wants to merge 2 commits into
Open
Nathnael Wondisha (ghost2023) wants to merge 2 commits into
Nathnael Wondisha (ghost2023) wants to merge 2 commits into
Conversation
Copilot started reviewing on behalf of
Nathnael Wondisha (ghost2023)
September 26, 2026 12:29
View session
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The targeted fix matches mapper usage and is covered by an appropriate regression test.
Review effort: Balanced
Findings: None
What changed in this PR
Fixes language-server memory retention after cloned program updates by removing unused closure references from the shared project-reference mapper.
Changes:
- Clears checker-pool and module-resolver factories from retained mapper options.
- Adds a GC-based regression test for cloned programs.
| File | Description |
|---|---|
tsc/internal/compiler/fileloader.go |
Prevents shared mapper options from retaining old projects. |
tsc/internal/project/snapshot_test.go |
Verifies pre-edit programs become collectible. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Author
|
@microsoft-github-policy-service agree |
This branch has not been deployed
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.
Fixes #64465
I was attempting to find a decrease the memory usage of the lsp and found a unneccessary clone of the program.
Problem
fileLoader.addProjectReferenceTasksstores the fullProgramOptionsonprojectReferenceFileMapper.ReuseProgramshares that mapper with every cloned program throughprocessedFiles. In the language server,opts.CreateCheckerPoolandopts.CreateModuleResolverare closures that capture the*project.Project, which creates this chain of references:As a result, after the first edit the program from before the edit, its checker pool and its checkers stay reachable for as long as any clone of it is alive. Its pool has already been
Discard()ed, so those checkers are never idle-cleaned either. The issue has the full analysis.Fix
The mapper only reads
Config,HostandUseSourceOfProjectReference, and never calls the factory closures. This change clearsCreateCheckerPoolandCreateModuleResolverfrom the copy of the options the mapper keeps. Behavior is otherwise unchanged.Results
I measured this with a scripted LSP client on a Next.js app of about 500 files with heavy use of type inference with Orpc. The client opens 5 files, requests diagnostics, hover and completion, and makes one edit. Heap is
inuse_spaceafter GC. Numbers are the average of 3 runs.Testing
Added
TestSnapshot/cloned program does not retain the program it was cloned from. It edits a file so the program is cloned, then asserts the pre-edit program is garbage-collected. The test fails without this change and passes with it.I ran the full npx hereby test, lint and check:format.
I have use AI for this PR. I fully reviewed the code and and understood it enough to be confident in it.