--incremental Made My TypeScript Hook 3.6x Slower. A 200KB Threshold Fixed It
I started freelancing in college at ¥100k a month, stacked side gigs up to ¥600k, then got laid off and dropped to zero overnight. Over the next six months I built an autonomous Claude Code setup from scratch, and it now runs at ¥1.2M a month in revenue. Of everything that went into that, the bug that quietly ate the most time was the one where I tried to make something faster and made it slower…
In his journey from freelancing in college to building a successful TypeScript hook, the author encountered a critical issue: making TypeScript faster led to slower performance. The key to this problem lies in how TypeScript compiles projects. When a developer edits a file, TypeScript runs a type check using the PostToolUse hook.
This process involves loading the entire dependency graph, which can be slow for larger projects. Initially, the author used the --incremental flag, which improved performance by only re-analyzing the changed files. However, this flag started to backfire on larger projects as the --tsbuildinfo cache file grew in size, making subsequent runs slower.
The author discovered that the 200KB threshold of this cache file correlated with project size and performance. When the cache exceeded 200KB, normal compilation mode became faster. By implementing a threshold guard, the hook automatically switches to normal mode for large projects and uses incremental mode for smaller ones. This solution optimizes performance across various project sizes, ensuring smoother development without sacrificing TypeScript's verification capabilities.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.