Performance Lab/ Experiment #001, opened October 2026
Typed events: the elegant type that slowed down every call site
Does a mapped type with an as clause, indexed at every call site, make type-checking measurably slower than inferring the event name from a generic parameter?
Verdict
Yes. Inferring the event name from the generic parameter cut check time by about 40% with TypeScript 6 and by about 65% with TypeScript 7, with the same type safety. Narrowing include to src also stopped TypeScript from reading a generated file the app never imports.
Takeaway
A mapped type with an as clause is evaluated backwards at each indexed call site. If you can infer the key from a generic instead, the checker does far less work.
Median check time
Results on Apple M3 Pro
Nov 9, 2026, 3 runs per condition, safety check passed. Apple M3 Pro, 12 cores, 36 GB, Node.js 22.23.3, Darwin 25.2.0.
| Condition | Check | Total | Peak RSS | Types | Instantiations |
|---|---|---|---|---|---|
| before (TypeScript 6.0.3) | 890 ms | 1.10 s | 282 MiB | 38,336 | 173,307 |
| after (TypeScript 6.0.3) | 430 ms | 560 ms | 225 MiB | 33,785 | 64,166 |
| before (TypeScript 7.0.2) | 330 ms | 349 ms | 200 MiB | 55,537 | 260,791 |
| after (TypeScript 7.0.2) | 143 ms | 166 ms | 112 MiB | 47,724 | 142,952 |
Results on Intel Xeon Processor @ 2.30GHz
Nov 3, 2026, 3 runs per condition, safety check passed. Intel(R) Xeon(R) Processor @ 2.30GHz, 1 core, 4 GB, Node.js 22.22.2, Linux 6.18.44-fc-v230.
| Condition | Check | Total | Peak RSS | Types | Instantiations |
|---|---|---|---|---|---|
| before (TypeScript 6.0.3) | 3.55 s | 4.53 s | n/a | 38,336 | 173,307 |
| after (TypeScript 6.0.3) | 2.11 s | 2.76 s | n/a | 33,785 | 64,166 |
| before (TypeScript 7.0.2) | 927 ms | 1.01 s | n/a | 55,537 | 260,791 |
| after (TypeScript 7.0.2) | 326 ms | 386 ms | n/a | 47,724 | 142,952 |
Reproduce it
Node.js 22 or later and git.
npm install && npm run lab:001