NewsCrawler.org

Dropping type inference for one Kysely query to cut TypeScript type-check load

型チェックが重かったので、クエリの型推論を手放してみた
Dropping type inference for one Kysely query to cut TypeScript type-check load
Dropping type inference for one Kysely query to cut TypeScript type-check load
Dropping type inference for one Kysely query to cut TypeScript type-check load
Image: zenn.dev

A product engineer at Dress Code ran low on memory and disk on a 24 GB Mac, and the TypeScript type check used 13326213K of memory (Memory used). Analysis showed that type inference for one Kysely[1] query accounted for about one third of the type-checking work across the project.

The query is about 540 lines long, with more than 50 joins, and when a controller's signature changed, 3,357 files were rechecked, 35% of that work being this query's inference. The team first fixed the return types to hand-written row types and added a type-level check to confirm they matched. It then stopped inference entirely by building the query with Kysely<any> and casting the results to the row types.

In a cold full check with --checkers 1, Instantiations[2] fell from 33,734,515 to 22,677,981 (-32.8%), Check time from 90.481s to 46.442s (-48.7%), and Memory used from 13326213K to 12511523K (-6.1%). The change removed 101 lines and added 17. The author notes that the measurement branch differed slightly in Files and Lines, so the scope was almost but not exactly the same.

Repository Kysely github.com

A type-safe TypeScript SQL query builder that lets you write database queries in code with compile-time checked results.

Stars: 14,382Forks: 463License: MITUpdated:

Read the original zenn.dev

Sources

  • Zenn JA

    型チェックが重かったので、クエリの型推論を手放してみた

    11 likes1 bookmark0 comments

Terms

  1. type inference — The compiler working out a value's type on its own from the code, instead of the type being written out explicitly.

Published: First seen: Читать по-русски

Open as a page