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?

Lab #001Confirmed−57%check time with TypeScript 7 after the fixComputed from medians, Nov 9, 2026. Verified on TypeScript 6.0.3 and TypeScript 7.0.2.

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

Before the fixAfter the fixMedian check time, lower is faster

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.

before (TypeScript 6.0.3)890 ms median
after (TypeScript 6.0.3)430 ms median
before (TypeScript 7.0.2)330 ms median
after (TypeScript 7.0.2)143 ms median

Bar: median check time. Bracket: fastest to slowest run. Bars share one scale within each workload (sources, checker count, full suite), not across workloads.

ConditionCheckTotalPeak RSSTypesInstantiations
before (TypeScript 6.0.3)890 ms1.10 s282 MiB38,336173,307
after (TypeScript 6.0.3)430 ms560 ms225 MiB33,78564,166
before (TypeScript 7.0.2)330 ms349 ms200 MiB55,537260,791
after (TypeScript 7.0.2)143 ms166 ms112 MiB47,724142,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.

before (TypeScript 6.0.3)3.55 s median
after (TypeScript 6.0.3)2.11 s median
before (TypeScript 7.0.2)927 ms median
after (TypeScript 7.0.2)326 ms median

Bar: median check time. Bracket: fastest to slowest run. Bars share one scale within each workload (sources, checker count, full suite), not across workloads.

ConditionCheckTotalPeak RSSTypesInstantiations
before (TypeScript 6.0.3)3.55 s4.53 sn/a38,336173,307
after (TypeScript 6.0.3)2.11 s2.76 sn/a33,78564,166
before (TypeScript 7.0.2)927 ms1.01 sn/a55,537260,791
after (TypeScript 7.0.2)326 ms386 msn/a47,724142,952

Reproduce it

Node.js 22 or later and git.

Source and raw results
npm install && npm run lab:001