Identifying Hot Types in Traces
What you'll learn: How to pinpoint which specific types are causing TypeScript's compiler to work the hardest by reading trace flame graphs.
The Investigation Phase
After you've generated a trace file using --generateTrace and loaded it into Chrome DevTools, you're looking at a visual representation of TypeScript's type-checking work. But with potentially thousands of operations, where do you focus your attention?
Hot types are the types that take the longest to instantiate or check. These are your performance bottlenecks—the types consuming disproportionate amounts of compile time.
Reading the Flame Graph
The flame graph displays horizontal bars representing work over time. The wider a bar, the more time that operation consumed. Look for:
- Wide bars that dominate the timeline
- Tall stacks showing deep instantiation chains
- Repeated patterns indicating the same type being checked many times
The trace labels each bar with the type operation being performed. You'll see entries like checkType, instantiateType, or specific type names from your codebase.
What Makes a Type "Hot"
A type becomes hot when it:
- Instantiates frequently (used in many places)
- Takes many steps to resolve (complex conditional logic, deep recursion)
- Creates large intermediate types (massive unions, distributed conditionals)
- Triggers cascading checks (changing it forces rechecking many dependents)
For example, a deeply recursive mapped type that processes string template literals might appear as a very wide bar because each level of recursion multiplies the work.
The Pattern Recognition Game
Once you identify a hot type by its visual dominance in the trace, cross-reference it with your source code. Common culprits include recursive utility types, overly clever generic constraints, and types that distribute over large unions.
The goal isn't to eliminate all expensive types—some complexity is necessary—but to find the ones where the cost doesn't match the value.
Key Takeaway: Hot types are the widest bars in your trace flame graph—identify them by visual dominance, then optimize those specific types to achieve meaningful compilation speedups.