Making my TypeScript types 15.7x faster A developer optimized TypeScript type inference in the Sury schema validation library, achieving up to 15.7x faster type extraction by reading a pre-resolved type field instead of matching the entire schema type. The fix reduced type instantiations for extracting S.Output from 7,842 to 501, and similar gains were seen across other operations. The optimization was guided by type instantiation benchmarks using @ark/attest and validated with type tests. If you opened this article, you probably already agree with me: sometimes TypeScript compiles painfully slowly. The same thing happened to @ chenglou https://x.com/ chenglou — an amazing dev who inspires me he worked on React, Messenger, ReasonML and ReScript, and currently Midjourney, Pretext . He's also a user of Sury https://github.com/DZakh/sury — the fastest schema validation library, which I maintain — and the author of this issue: "Large TS types cause type inference slowdown" https://github.com/DZakh/sury/issues/166 . That's... not nice. But I knew ArkType https://arktype.io exists, and that people have built wild things in TS's type system Doom included . So the slowness was clearly solvable, not fundamental. Here's the recipe I used. You can apply it to your own library. Before we begin, here are the results. These are type-instantiation counts, measured with @ark/attest https://github.com/arktypeio/arktype/tree/main/ark/attest : | Operation | Before | After | Faster | |---|---|---|---| | Define a 10-field object | 1409 | 343 | 4.1× | | Define a 5-field object mixed optional | 17916 | 10557 | 1.7× | | Define a 3-level nested object | 31013 | 20419 | 1.5× | | Define a union of 5 objects | 67580 | 53173 | 1.3× | Extract S.Output 5-field object | 7842 | 501 | 15.7× | Extract S.Input 5-field object | 6767 | 501 | 13.5× | Extract S.Output nested object | 7732 | 501 | 15.4× | Define + extract 10-field object | 9446 | 844 | 11.2× | | Merge + extract output | 13651 | 7039 | 1.9× | The title comes from that 15.7× on S.Output . Extraction is the operation you hit most often: every type X = S.Output