Repository navigation
High memory consumption in tsc (~8 GB) causing red memory pressure and swap thrashing on 16 GB Apple Silicon (M4) #18201
Replies: 2 comments
Root Cause Update & Proposed FixesFollowing up after deeper profiling into the process tree and repository history: 1.
|
Proposal: Auto-Optimization Architecture (T3 Code Perspective)Following up on the root-cause diagnosis, rather than requiring individual developers on 16 GB Apple Silicon Macs to manually discover and export shell variables ( flowchart TD
Hardware["Hardware Probing (os.totalmem & os.cpus)"] --> Profile["Adaptive Resource Profiler"]
Profile --> Runner["1. scripts/dev-runner.ts & Repo Scripts"]
Profile --> Server["2. T3 Code Host Process Layer (apps/server & Desktop)"]
Profile --> LSP["3. Language Service / Extension Settings"]
subgraph Auto_Tuning ["Auto-Tuned Variables"]
Runner --> V1["GOMEMLIMIT: ~25% RAM (3GiB on 16GB)"]
Runner --> V2["GOMAXPROCS: Capped to 4 on 16GB"]
Runner --> V3["GOGC: 60 (more aggressive GC)"]
Runner --> V4["NODE_OPTIONS: --max-old-space-size"]
end
1. Hardware-Aware Adaptive Profiler (
|
Uh oh!
There was an error while loading. Please reload this page.
Summary
When running typecheck / build tasks on Apple Silicon (tested on an M4 Mac with 16 GB unified memory), the TypeScript compiler (
tsc) balloons up to ~8 GB of memory (Activity Monitor reports 7.99 GB). This sends macOS memory pressure into the critical red zone and pushes the system into heavy swap thrashing (6.46 GB swap, 5.93 GB compressed memory).As a result, system responsiveness drops sharply and other applications hang or become unresponsive (e.g.,
Microsoft Word (Not Responding)).Evidence & System State
Process Details (
tscPID 90385)node_modules/.pnpm/typescript@.../bin/tscnode(PID 90357)System Memory Metrics (16.00 GB Physical RAM)
Likely Factors
The monorepo relies heavily on Effect schemas, services, and large union/intersection types across
apps/server,packages/client-runtime, andpackages/contracts. Deep recursive type inference or un-memoized intermediate types can causetsc's internal type caches and ASTs to expand dramatically.While root scripts cap concurrency (e.g.
vp run -r --concurrency-limit 2 typecheck), concurrent typechecking across large packages without conservative Node heap limits (--max-old-space-size) can quickly overwhelm a 16 GB machine when running alongside normal development workloads.Suggested Directions & Mitigations
tsc --generateTraceand inspect with@typescript/analyze-traceto identify which files and symbols consume the most check time and instantiate the most types.tsc --extendedDiagnosticson the heaviest packages (apps/server,packages/client-runtime) to check memory and instantiation counts.Questions:
tscmemory spikes or extreme memory pressure during local typechecking or build runs on 16 GB Macs?All reactions