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.
Page URL: https://github.com/microsoft/TypeScript-Website/blob/v2/packages/typescript-vfs/src/index.ts (
@typescript/vfs)Issue:
createVirtualTypeScriptEnvironmentpermanently stores a second parsed AST for every file, roughly doubling per-file memory.Where the duplicates are created:
createFile/updateFileparse aSourceFile(ts.createSourceFile/ts.updateSourceFile) and pass it down tocreateVirtualCompilerHost'supdateFile, which saves it in its internalsourceFilesmap.getScriptSnapshotreads text fromsys, and the language service parses and caches its ownSourceFiles from those snapshots.So the ASTs in the compiler-host map are write-only: every file that goes through
env.createFile/env.updateFileis 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.