Reducing Zod's Memory Footprint by an Order of Magnitude with Method Memoization
Zod 1 month ago 37
Zod 4.5 added method memoization so Zod schema methods are only bound and allocated on first use instead of being eagerly created for every instance. A bare z.string() drops retained heap from 7.5kb in Zod 4.4 to 784 bytes in Zod 4.5. This reduces per-instance memory use by deferring method allocations that would otherwise inflate V8’s own-property backing store, while still keeping methods safely bound.