@typescript/vfs: createVirtualTypeScriptEnvironment stores a duplicate SourceFile per file that the language service never reads

Open
#3,614 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
68/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
typescript
Domain
tooling

Research direction

Start in packages/typescript-vfs/src/index.ts and trace createVirtualTypeScriptEnvironment's createFile/updateFile calls into createVirtualCompilerHost's updateFile. Confirm how the sourceFiles map is populated and whether the language service reads it. Done means eliminating the unused duplicate SourceFile storage without changing language-service behavior; run the package's existing tests if available.

Written by the indexing model from the issue text.

Description

Page URL: https://github.com/microsoft/TypeScript-Website/blob/v2/packages/typescript-vfs/src/index.ts (@typescript/vfs)

Issue:

createVirtualTypeScriptEnvironment permanently stores a second parsed AST for every file, roughly doubling per-file memory.

Where the duplicates are created:

  • The env's createFile/updateFile parse a SourceFile (ts.createSourceFile / ts.updateSourceFile) and pass it down to createVirtualCompilerHost's updateFile, which saves it in its internal sourceFiles map.
  • The language service never reads that map — its host's getScriptSnapshot reads text from sys, and the language service parses and caches its own SourceFiles from those snapshots.

So the ASTs in the compiler-host map are write-only: every file that goes through env.createFile/env.updateFile is held as two full ASTs (the language service's copy plus the map's copy), and the map's copy is never released for the lifetime of the env.

Dominant language
TypeScript
Stars
2.6k
Forks
1.5k
Avg merge
1d 12h
Merged PRs (30d)
5

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/TypeScript-Website

All issues in microsoft/TypeScript-Website

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.