Heap growth in TypeScript Builder during incremental compilation with project references
0 reputation · 02 Jan 2022, 09:31 UTC
Memory usage in composite projects
In TypeScript environments utilizing --incremental and --composite flags, the Builder component manages the lifecycle of SourceFile objects to optimize rebuild speeds. While TypeScript 4.5 introduced mechanisms to dispose of outdated nodes during the clean phase, specific behaviors persist in complex dependency graphs.
When a composite project references another composite project, there is uncertainty regarding how the language service handles transitive dependency changes. If the Builder prioritizes compilation speed over full correctness, stale type information may remain in the IDE despite the memory leak mitigations.
Given a multi-project setup running in watch mode, how does the compiler ensure that transitive changes trigger the necessary cache invalidation across all upstream projects? Does the current reference counting mechanism in the Program object fully prevent heap growth when deep dependency chains are modified frequently?