ITADN

TypeBox 1 Compile is significantly slower than TypeBox 0.34

#1563ClosedSaltyAom 创建于 2026-04-06
review
S
SaltyAomcommented
TypeBox 1 Compile is 10x slower and use significantly more memory than TypeBox 0.34 compile. TypeBox 0.34 using `TypeCompiler.Compile` ```ts import { Type } from '@sinclair/typebox' import { TypeCompiler } from '@sinclair/typebox/compiler' const schema = Type.String() const stacks = <any[]>[] const t1 = performance.now() const m1 = process.memoryUsage().heapUsed for (let i = 0; i <= 100_000; i++) stacks.push(TypeCompiler.Compile(schema)) const m2 = process.memoryUsage().heapUsed const t2 = performance.now() console.log('Time:', t2 - t1, 'ms') console.log('Memory:', (m2 - m1) / 1024 / 1024, 'MB') ``` TypeBox 1 using either `typebox/schema` or `typebox/compile` ```ts import { Type } from 'typebox' import { Compile } from 'typebox/schema' const schema = Type.String() const stacks = <any[]>[] const t1 = performance.now() const m1 = process.memoryUsage().heapUsed for (let i = 0; i <= 100_000; i++) stacks.push(Compile(schema)) const m2 = process.memoryUsage().heapUsed const t2 = performance.now() console.log('Time:', t2 - t1, 'ms') console.log('Memory:', (m2 - m1) / 1024 / 1024, 'MB') ``` This would produce the result as follows | Method | Time | Memory | | --- | --- | --- | | TypeBox 0.34 | 228 ms | 108 MB | | TypeBox 1 `typebox/schema` | 2259 ms | 226 MB | | TypeBox 1 `typebox/compile` | 2232 ms | 230 MB | TypeBox 1 compile is slower than TypeBox 0.34 by 10x and consumes more memory usage by 2x This happens in both Node and Bun - Bun: 1.3.11 - Node: 24.14.0 Benchmark on M1 Max 64GB - `Darwin 25.3.0 arm64 arm` TypeBox version: - `@sinclair/typebox` - 0.34.49 - `typebox` - 1.1.16 Additional note: - This is reproducible on a newly created project - This happens starting from TypeBox 1.0.0 <details> <summary>Attached images from running</summary> <br> TypeBox 1 `typebox/schema` ![TypeBox 1 running](https://github.com/user-attachments/assets/17783df3-1bd8-4c64-904e-aeb489b75965) TypeBox 0.34 `@sinclair/typebox/compiler` ![TypeBox 0.34 running](https://github.com/user-attachments/assets/a0f905b7-bb83-4d38-9acc-c171c5b1d393) </details>
关闭于 2026-04-08 4 条评论