1 line
63 KiB
JSON
1 line
63 KiB
JSON
{"success":true,"data":{"web":[{"url":"https://zod.dev/packages/mini","title":"Zod Mini","description":"The next bundle size tested is 128kb , which added only 5ms . When gzipped, the bundle size for the entirely of regular Zod is roughly 17kb , which would ...","position":1,"markdown":"💎 Zod 4 is now stable! [Read the announcement.](https://zod.dev/v4)\n\nAsk AI\n\n\n# Zod Mini\n\nCopy markdown\n[Edit this page](https://github.com/colinhacks/zod/edit/main/packages/docs/content/packages/mini.mdx)\n\n**Note** — The docs for Zod Mini are interleaved with the regular Zod docs via tabbed code blocks. This page is designed to explain why Zod Mini exists, when to use it, and some key differences from regular Zod.\n\nZod Mini variant was introduced with the release of Zod 4. To try it:\n\n```\nnpm install zod@^4.0.0\n```\n\nTo import it:\n\n```\nimport * as z from \"zod/mini\";\n```\n\nZod Mini implements the exact same functionality as `zod`, but using a _functional_, _tree-shakable_ API. If you're coming from `zod`, this means you generally will use _functions_ in place of methods.\n\n```\n// regular Zod\nconst mySchema = z.string().optional().nullable();\n\n// Zod Mini\nconst mySchema = z.nullable(z.optional(z.string()));\n```\n\n## [Tree-shaking](https://zod.dev/packages/mini?id=tree-shaking)\n\nTree-shaking is a technique used by modern bundlers to remove unused code from the final bundle. It's also referred to as _dead-code elimination_.\n\nIn regular Zod, schemas provide a range of convenience methods to perform some common operations (e.g. `.min()` on string schemas). Bundlers are generally not able to remove (\"treeshake\") unused method implementations from your bundle, but they are able to remove unused top-level functions. As such, the API of Zod Mini uses more functions than methods.\n\n```\n// regular Zod\nz.string().min(5).max(10).trim()\n\n// Zod Mini\nz.string().check(z.minLength(5), z.maxLength(10), z.trim());\n```\n\nTo give a general idea about the bundle size reduction, consider this simple script:\n\n```\nz.boolean().parse(true)\n```\n\nBundling this with Zod and Zod Mini results in the following bundle sizes. Zod Mini results in a 64% reduction.\n\n| Package | Bundle size (gzip) |\n| --- | --- |\n| Zod Mini | `2.12kb` |\n| Zod | `5.91kb` |\n\nWith a marginally more complex schema that involves object types:\n\n```\nconst schema = z.object({ a: z.string(), b: z.number(), c: z.boolean() });\n\nschema.parse({\n a: \"asdf\",\n b: 123,\n c: true,\n});\n```\n\n| Package | Bundle size (gzip) |\n| --- | --- |\n| Zod Mini | `4.0kb` |\n| Zod | `13.1kb` |\n\nThis gives you a sense of the bundle sizes involved. Look closely at these numbers and run your own benchmarks to determine if using Zod Mini is worth it for your use case.\n\n## [When (not) to use Zod Mini](https://zod.dev/packages/mini?id=when-not-to-use-zod-mini)\n\nIn general you should probably use regular Zod unless you have uncommonly strict constraints around bundle size. Many developers massively overestimate the importance of bundle size to application performance. In practice, bundle size on the scale of Zod (`5-10kb` typically) is only a meaningful concern when optimizing front-end bundles for a user base with slow mobile network connections in rural or developing areas.\n\nLet's run through some considerations:\n\n### [DX](https://zod.dev/packages/mini?id=dx)\n\nThe API of Zod Mini is more verbose and less discoverable. The methods in Zod's API are much easier to discover & autocomplete through Intellisense than the top-level functions in Zod Mini. It isn't possible to quickly build a schema with chained APIs. (Speaking as the creator of Zod: I spent a lot of time designing the Zod Mini API to be as ergonomic as possible, but I still have a strong preference the standard Zod API.)\n\n### [Backend development](https://zod.dev/packages/mini?id=backend-development)\n\nIf you are using Zod on the backend, bundle size on the scale of Zod is not meaningful. This is true even in resource-constrained environments like Lambda. [This post](https://medium.com/@adtanasa/size-is-almost-all-that-matters-for-optimizing-aws-lambda-cold-starts-cad54f65cbb) benchmarks cold start times with bundles of various sizes. Here is a subset of the results:\n\n| Bundle size | Lambda cold start time |\n| --- | --- |\n| `1kb` | `171ms` |\n| `17kb` (size of gzipped non-Mini Zod) | `171.6ms` (interpolated) |\n| `128kb` | `176ms` |\n| `256kb` | `182ms` |\n| `512kb` | `279ms` |\n| `1mb` | `557ms` |\n\nThe minimum cold start time for a negligible `1kb` bundle is `171ms`. The next bundle size tested is `128kb`, which added only `5ms`. When gzipped, the bundle size for the entirely of regular Zod is roughly `17kb`, which would correspond to a `0.6ms` increase in startup time.\n\n### [Internet speed](https://zod.dev/packages/mini?id=internet-speed)\n\nGenerally, the round trip time to the server (`100-200ms`) will dwarf the time required to download an additional `10kb`. Only on slow 3G connections (sub-`1Mbps`) does the download time for an additional `10kb` become more significant. If you aren't optimizing specifically for users in rural or developing areas, your time is likely better spent optimizing something else.\n\n## [`ZodMiniType`](https://zod.dev/packages/mini?id=zodminitype)\n\nAll Zod Mini schemas extend the `z.ZodMiniType` base class, which in turn extends `z.core.$ZodType` from [`zod/v4/core`](https://zod.dev/packages/core). While this class implements far fewer methods than `ZodType` in `zod`, some particularly useful methods remain.\n\n### [`.parse`](https://zod.dev/packages/mini?id=parse)\n\nThis is an obvious one. All Zod Mini schemas implement the same parsing methods as `zod`.\n\n```\nimport * as z from \"zod/mini\"\n\nconst mySchema = z.string();\n\nmySchema.parse('asdf')\nawait mySchema.parseAsync('asdf')\nmySchema.safeParse('asdf')\nawait mySchema.safeParseAsync('asdf')\n```\n\n### [`.check()`](https://zod.dev/packages/mini?id=check)\n\nIn regular Zod there are dedicated methods on schema subclasses for performing common checks:\n\n```\nimport * as z from \"zod\";\n\nz.string()\n .min(5)\n .max(10)\n .refine(val => val.includes(\"@\"))\n .trim()\n```\n\nIn Zod Mini such methods aren't implemented. Instead you pass these checks into schemas using the `.check()` method:\n\n```\nimport * as z from \"zod/mini\"\n\nz.string().check(\n z.minLength(5),\n z.maxLength(10),\n z.refine(val => val.includes(\"@\")),\n z.trim()\n);\n```\n\nThe following checks are implemented. Some of these checks only apply to schemas of certain types (e.g. strings or numbers). The APIs are all type-safe; TypeScript won't let you add an unsupported check to your schema.\n\n```\nz.lt(value);\nz.lte(value); // alias: z.maximum()\nz.gt(value);\nz.gte(value); // alias: z.minimum()\nz.positive();\nz.negative();\nz.nonpositive();\nz.nonnegative();\nz.multipleOf(value);\nz.maxSize(value);\nz.minSize(value);\nz.size(value);\nz.maxLength(value);\nz.minLength(value);\nz.length(value);\nz.regex(regex);\nz.lowercase();\nz.uppercase();\nz.includes(value);\nz.startsWith(value);\nz.endsWith(value);\nz.property(key, schema);\nz.mime(value);\n\n// custom checks\nz.refine()\nz.check() // replaces .superRefine()\n\n// mutations (these do not change the inferred types)\nz.overwrite(value => newValue);\nz.normalize();\nz.trim();\nz.toLowerCase();\nz.toUpperCase();\n\n// metadata (registers schema in z.globalRegistry)\nz.meta({ title: \"...\", description: \"...\" });\nz.describe(\"...\");\n```\n\n### [`.register()`](https://zod.dev/packages/mini?id=register)\n\nFor registering a schema in a [registry](https://zod.dev/metadata#registries).\n\n```\nconst myReg = z.registry<{title: string}>();\n\nz.string().register(myReg, { title: \"My cool string schema\" });\n```\n\n### [`.brand()`](https://zod.dev/packages/mini?id=brand)\n\nFor _branding_ a schema. Refer to the [Branded types](https://zod.dev/api#branded-types) docs for more information.\n\n```\nimport * as z from \"zod/mini\"\n\nconst USD = z.string().brand(\"USD\");\n```\n\n### [`.clone(def)`](https://zod.dev/packages/mini?id=clonedef)\n\nReturns an identical clone of the current schema using the provided `def`.\n\n```\nconst mySchema = z.string()\n\nmySchema.clone(mySchema._zod.def);\n```\n\n## [No default locale](https://zod.dev/packages/mini?id=no-default-locale)\n\nWhile regular Zod automatically loads the English (`en`) locale, Zod Mini does not. This reduces the bundle size in scenarios where error messages are unnecessary, localized to a non-English language, or otherwise customized.\n\nThis means, by default the `message` property of all issues will simply read `\"Invalid input\"`. To load the English locale:\n\n```\nimport * as z from \"zod/mini\"\n\nz.config(z.locales.en());\n```\n\nRefer to the [Locales](https://zod.dev/error-customization#internationalization) docs for more on localization.\n\n[Zod\\\\\n\\\\\nInternals and structure of the Zod library](https://zod.dev/packages/zod) [Zod Core\\\\\n\\\\\nZod Core package - minimal core functionality for custom implementations](https://zod.dev/packages/core)\n\n### On this page\n\n[Tree-shaking](https://zod.dev/packages/mini#tree-shaking) [When (not) to use Zod Mini](https://zod.dev/packages/mini#when-not-to-use-zod-mini) [DX](https://zod.dev/packages/mini#dx) [Backend development](https://zod.dev/packages/mini#backend-development) [Internet speed](https://zod.dev/packages/mini#internet-speed) [`ZodMiniType`](https://zod.dev/packages/mini#zodminitype) [`.parse`](https://zod.dev/packages/mini#parse) [`.check()`](https://zod.dev/packages/mini#check) [`.register()`](https://zod.dev/packages/mini#register) [`.brand()`](https://zod.dev/packages/mini#brand) [`.clone(def)`](https://zod.dev/packages/mini#clonedef) [No default locale](https://zod.dev/packages/mini#no-default-locale)","metadata":{"ogImage":"https://zod.dev/og.png?title=Zod%20Mini&description=Zod%20Mini%20-%20a%20tree-shakable%20Zod&path=zod.dev%2Fpackages%2Fmini","viewport":"width=device-width, initial-scale=1","ogUrl":"https://zod.dev/packages/mini","og:url":"https://zod.dev/packages/mini","ogSiteName":"Zod","twitter:image:height":"630","twitter:site":"@colinhacks","og:image:height":"630","og:image:width":"1200","next-size-adjust":"","twitter:image":"https://zod.dev/og.png?title=Zod%20Mini&description=Zod%20Mini%20-%20a%20tree-shakable%20Zod&path=zod.dev%2Fpackages%2Fmini","ogDescription":"Zod Mini - a tree-shakable Zod","og:title":"Zod Mini | Zod","og:image:alt":"Zod Mini | Zod","og:type":"website","twitter:title":"Zod Mini | Zod","og:site_name":"Zod","twitter:description":"Zod Mini - a tree-shakable Zod","twitter:creator":"@colinhacks","language":"en","og:image":"https://zod.dev/og.png?title=Zod%20Mini&description=Zod%20Mini%20-%20a%20tree-shakable%20Zod&path=zod.dev%2Fpackages%2Fmini","twitter:card":"summary_large_image","keywords":"zod,typescript,validation,schema","og:description":"Zod Mini - a tree-shakable Zod","twitter:image:width":"1200","description":"Zod Mini - a tree-shakable Zod","title":"Zod Mini | Zod","ogTitle":"Zod Mini | Zod","twitter:image:alt":"Zod Mini | Zod","favicon":"https://zod.dev/icon.png?39fe259ddd7f4224","scrapeId":"019d3953-c386-760f-971d-e2f43a08ed61","sourceURL":"https://zod.dev/packages/mini","url":"https://zod.dev/packages/mini","statusCode":200,"contentType":"text/html; charset=utf-8","timezone":"America/New_York","proxyUsed":"basic","cacheState":"miss","indexId":"bfa79dc9-d51c-4084-a35f-2301913bf773","creditsUsed":1}},{"url":"https://www.reddit.com/r/typescript/comments/1kqka6e/introducing_zod_4/","title":"Introducing Zod 4 : r/typescript - Reddit","description":"Zod mini allows for a smaller bundle size, which is good for client side usage. The main reason for continuing the classic API is preference.","position":2},{"url":"https://github.com/colinhacks/zod/issues/4637","title":"4x bundle size increase with CommonJS for v4 and v4-mini vs v3","description":"There's a lot of highly compressible code in Zod 4 because there are parallel declarations (e.g. ZodMiniString extends $ZodString , etc.). Gzip/ ...","position":3,"category":"github","markdown":"[Skip to content](https://github.com/colinhacks/zod/issues/4637#start-of-content)\n\nYou signed in with another tab or window. [Reload](https://github.com/colinhacks/zod/issues/4637) to refresh your session.You signed out in another tab or window. [Reload](https://github.com/colinhacks/zod/issues/4637) to refresh your session.You switched accounts on another tab or window. [Reload](https://github.com/colinhacks/zod/issues/4637) to refresh your session.Dismiss alert\n\n{{ message }}\n\n[colinhacks](https://github.com/colinhacks)/ **[zod](https://github.com/colinhacks/zod)** Public\n\n- [Sponsor](https://github.com/sponsors/colinhacks)\n- [Notifications](https://github.com/login?return_to=%2Fcolinhacks%2Fzod) You must be signed in to change notification settings\n- [Fork\\\\\n1.9k](https://github.com/login?return_to=%2Fcolinhacks%2Fzod)\n- [Star\\\\\n42.2k](https://github.com/login?return_to=%2Fcolinhacks%2Fzod)\n\n\n# 4x bundle size increase with CommonJS for v4 and v4-mini vs v3\\#4637\n\n[New issue](https://github.com/login?return_to=https://github.com/colinhacks/zod/issues/4637)\n\nCopy link\n\n[New issue](https://github.com/login?return_to=https://github.com/colinhacks/zod/issues/4637)\n\nCopy link\n\nClosed\n\nClosed\n\n[4x bundle size increase with CommonJS for v4 and v4-mini vs v3](https://github.com/colinhacks/zod/issues/4637#top)#4637\n\nCopy link\n\n[](https://github.com/paulbrimicombe)\n\n## Description\n\n[](https://github.com/paulbrimicombe)\n\n[paulbrimicombe](https://github.com/paulbrimicombe)\n\nopened [on Jun 6, 2025on Jun 6, 2025](https://github.com/colinhacks/zod/issues/4637#issue-3125150742) · edited by [paulbrimicombe](https://github.com/paulbrimicombe)\n\nEdits\n\nIssue body actions\n\nWhen `zod` v3 is used in a CommonJS codebase that uses `esbuild`, `rollup` or `webpack` to package and minify code, the bundle size contribution of `zod` is ~68K which is pretty good. When v4 or v4-mini is used, the bundle size contribution increases more than 4x with the same project setup.\n\nI've [done some experiments](https://github.com/paulbrimicombe/zod-bundle-sizes) with different bundlers and different versions of `zod` and here are some results:\n\n| Zod version | Module system | ESBuild bundle size | Rollup bundle size | Webpack bundle size |\n| --- | --- | --- | --- | --- |\n| v3 | CommonJS | 68K | 68K | 68K |\n| v4 | CommonJS | 288K | 255K | 254K |\n| v4-mini | CommonJS | 279K | 246K | 245K |\n| v3 | ESM | 55K | 52K | 52K |\n| v4 | ESM | 41K | 33K | 35K |\n| v4-mini | ESM | ~~41K~~ 6K | ~~33K~~ 5K | ~~35K~~ 6K |\n\nThis is a fairly major increase for anyone using this fairly common project setup (not just for front-end bundles — anyone using something like AWS Lambda will get slower cold starts due to the increased bundle size).\n\nNote\n\nESM + `v4-mini` sizes fixed base on [paulbrimicombe/zod-bundle-sizes#1](https://github.com/paulbrimicombe/zod-bundle-sizes/pull/1)\n\n## Activity\n\n[colinhacks](https://github.com/colinhacks)\n\nclosed this as [completed](https://github.com/colinhacks/zod/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted) [on Jun 6, 2025on Jun 6, 2025](https://github.com/colinhacks/zod/issues/4637#event-18026878547)\n\n[colinhacks](https://github.com/colinhacks)\n\nreopened this [on Jun 6, 2025on Jun 6, 2025](https://github.com/colinhacks/zod/issues/4637#event-18026907483)\n\n[](https://github.com/colinhacks)\n\n### colinhacks commented on Jun 6, 2025on Jun 6, 2025\n\n[](https://github.com/colinhacks)\n\n[colinhacks](https://github.com/colinhacks)\n\n[on Jun 6, 2025on Jun 6, 2025](https://github.com/colinhacks/zod/issues/4637#issuecomment-2950064668) · edited by [colinhacks](https://github.com/colinhacks)\n\nEdits\n\nOwner\n\nMore actions\n\nYou're not using Zod Mini in your ESM test which is why the mini and non-mini numbers are identical. I made a PR here: [paulbrimicombe/zod-bundle-sizes#1](https://github.com/paulbrimicombe/zod-bundle-sizes/pull/1)\n\nI'd like to link you and anyone else who's reading this to my comment here: [#4433 (comment)](https://github.com/colinhacks/zod/issues/4433#issuecomment-2921500831) I'm sorry if I come off as snippy, but I'm really tired of this discussion.\n\n1/ `import *`\n\nAs you say in your readme, you need to do `import *` to get treeshaking with esbuild and apparently Next.js's webpack variant. This is known: [#4569](https://github.com/colinhacks/zod/pull/4569) I generally assume that people who care a lot about tree-shaking will know to do `import *`.\n\n2/ These sizes also aren't gzipped, which isn't representative of a production scenario. There's a lot of highly compressible code in Zod 4 because there are parallel declarations (e.g. `ZodMiniString` extends `$ZodString`, etc.). Gzip/DEFLATE does a good job of eliminating some of the inherent redundancy there. All of Zod Standard zips down to ~17kb.\n\n3/ Lambda\n\n> anyone using something like AWS Lambda will get slower cold starts due to the increased bundle size).\n\nI cannot emphasize enough that bundle size changes on the scale of 10kb are negligible to Lambda cold starts. There are a lot of people and blog posts who spread this notion around with zero nuance, and it's maddening and irresponsible. A change of 50kb corresponds to about `1ms`. The floor on cold starts with Node.js is 170ms for a hello world script. Charts: [https://gist.github.com/adriantanasa/d9cb9f7313f985f180c0aec98e482f2b#file-nodejs18-reference-logs-insights-results-csv](https://gist.github.com/adriantanasa/d9cb9f7313f985f180c0aec98e482f2b#file-nodejs18-reference-logs-insights-results-csv)\n\nYou're almost certainly better off optimizing for something else, or at least directing your bundle size concerns towards a different dependency that isn't already negligible in size.\n\n* * *\n\nNothing actionable, closing.\n\n[colinhacks](https://github.com/colinhacks)\n\nclosed this as [completed](https://github.com/colinhacks/zod/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted) [on Jun 6, 2025on Jun 6, 2025](https://github.com/colinhacks/zod/issues/4637#event-18027445273)\n\n[](https://github.com/paulbrimicombe)\n\n### paulbrimicombe commented on Jun 8, 2025on Jun 8, 2025\n\n[](https://github.com/paulbrimicombe)\n\n[paulbrimicombe](https://github.com/paulbrimicombe)\n\n[on Jun 8, 2025on Jun 8, 2025](https://github.com/colinhacks/zod/issues/4637#issuecomment-2954035359)\n\nAuthor\n\nMore actions\n\nFirstly, thanks for taking the time to look into this and for the quick response [@colinhacks](https://github.com/colinhacks) .\n\n> You're not using Zod Mini in your ESM test which is why the mini and non-mini numbers are identical. I made a PR here: [paulbrimicombe/zod-bundle-sizes#1](https://github.com/paulbrimicombe/zod-bundle-sizes/pull/1)\n\nApologies for this — I ran through so many tests / combinations and missed this before committing. I'll merge that PR and I've fixed the numbers in the table above just in case anyone finds this issue in the future.\n\n> I'd like to link you and anyone else who's reading this to my comment here: [#4433 (comment)](https://github.com/colinhacks/zod/issues/4433#issuecomment-2921500831) I'm sorry if I come off as snippy, but I'm really tired of this discussion.\n\nNo need to apologise. Maintaining a popular open source library is hard work and we're very grateful that you do.\n\n> 1/ `import *`\n>\n> As you say in your readme, you need to do `import *` to get treeshaking with esbuild and apparently Next.js's webpack variant. This is known: [#4569](https://github.com/colinhacks/zod/pull/4569) I generally assume that people who care a lot about tree-shaking will know to do `import *`.\n\nI wonder whether updating the examples in the `zod-mini` docs (or at least a quick mention of this slightly odd behaviour) might stave off some of these comments or issues: [https://zod.dev/v4?id=introducing-zod-mini](https://zod.dev/v4?id=introducing-zod-mini)\n\n> 2/ These sizes also aren't gzipped, which isn't representative of a production scenario. There's a lot of highly compressible code in Zod 4 because there are parallel declarations (e.g. `ZodMiniString` extends `$ZodString`, etc.). Gzip/DEFLATE does a good job of eliminating some of the inherent redundancy there. All of Zod (core + standard + mini, no treeshaking) zips down to ~49kb.\n\nPoint taken.\n\n> 3/ Lambda\n>\n> > anyone using something like AWS Lambda will get slower cold starts due to the increased bundle size).\n>\n> I cannot emphasize enough that bundle size changes on the scale of 10kb are negligible to Lambda cold starts. There are a lot of people and blog posts who spread this notion around with zero nuance, and it's maddening and irresponsible. A change of 50kb corresponds to about `1ms`. The floor on cold starts with Node.js is 170ms for a hello world script. Charts [https://gist.github.com/adriantanasa/d9cb9f7313f985f180c0aec98e482f2b#file-nodejs18-reference-logs-insights-results-csv](https://gist.github.com/adriantanasa/d9cb9f7313f985f180c0aec98e482f2b#file-nodejs18-reference-logs-insights-results-csv)\n>\n> You're almost certainly better off optimizing for something else, or at least directing your bundle size concerns towards a different dependency that isn't already negligible in size.\n\nUnfortunately for anyone using CommonJS, the bundle size increase is more like ~190K than 10K and we've found that this can have a significant impact on cold start times — I'll run a few benchmarks when I get time and post some results. The length of time partly depends on what's in the Lambda bundle — if it's JS code that is parsed at startup the impact is higher, whereas if it's a data file, the impact is much, much lower. I'll run some tests directly with v3 and v4 of `zod` and post some results.\n\n👀React with 👀2colinhacks and manuelpuyol\n\n[dosubot](https://github.com/apps/dosubot)\n\nmentioned this [on Jul 2, 2025on Jul 2, 2025](https://github.com/colinhacks/zod/issues/4637#event-2703672532)\n\n- [V4 is large size #4798](https://github.com/colinhacks/zod/issues/4798)\n\n\n[](https://github.com/paulbrimicombe)\n\n### paulbrimicombe commented on Jul 28, 2025on Jul 28, 2025\n\n[](https://github.com/paulbrimicombe)\n\n[paulbrimicombe](https://github.com/paulbrimicombe)\n\n[on Jul 28, 2025on Jul 28, 2025](https://github.com/colinhacks/zod/issues/4637#issuecomment-3127359408)\n\nAuthor\n\nMore actions\n\nApologies for the delay [@colinhacks](https://github.com/colinhacks) but I finally managed to find the time to do some experiments on Lambda.\n\n## Setup\n\n- Create a package with `zod` as the only dependency\n\n- Create a handler function that is _very_ naive (a similar handler function was used for CommonJS):\n\n\n\n```\nimport { z } from \"zod/v3\";\n\nexport const handler = () => {\n console.log(\"ESM; zod/v3\", Object.keys(z).length);\n};\n```\n\n\n\n\n\n\n - I realise that this is not realistic use of `zod` but I wanted to simulate a package that needs all of the `zod` functions as a starting point. If you'd like to suggest a different handler function, please let me know.\n- Lambda function spec is:\n - 1024MB\n - `arm64`\n - `nodejs22.x`\n- Create various Lambda bundles:\n - Different `zod` versions / imports (`@3` vs `zod/v3` vs `zod/v4` vs `zod/mini`).\n - Unbundled (i.e. dependencies are still in `node_modules` and code is not minified) and bundled/minified with `esbuild`.\n - CommonJS and ESM.\n- For each Lambda version, invoke the (cold) function 15 times in parallel to trigger cold starts (stats below are based on 15 data points each)\n\n- Collect stats from the `@initDuration` in the Lambda `REPORT` log line\n\n\n## Results\n\n### ESM + no bundling\n\n| `zod` version | import | Init time p10 | Init time p50 | Init time p90 | p50 change vs [@3](https://github.com/3) |\n| --- | --- | --- | --- | --- | --- |\n| 3.25.76 | `import {z} from 'zod'` | 177 ms | 184 ms | 199 ms | 0% |\n| 4.0.10 | `import {z} from 'zod/v3'` | 177 ms | 187 ms | 212 ms | +2% |\n| 4.0.10 | `import {z} from 'zod/v4'` | 260 ms | 268 ms | 271 ms | +46% |\n| 4.0.10 | `import {z} from 'zod/mini'` | 254 ms | 258 ms | 284 ms | +40% |\n\n- Cold start time increases by ~40% for v4 compared to v3.\n\n### ESM + `esbuild`\n\n| `zod` version | import | Init time p10 | Init time p50 | Init time p90 | p50 change vs [@3](https://github.com/3) |\n| --- | --- | --- | --- | --- | --- |\n| 3.25.76 | `import {z} from 'zod'` | 147 ms | 154 ms | 184 ms | 0% |\n| 4.0.10 | `import {z} from 'zod/v3'` | 146 ms | 154 ms | 193 ms | 0% |\n| 4.0.10 | `import {z} from 'zod/v4'` | 170 ms | 181 ms | 196 ms | +18% |\n| 4.0.10 | `import {z} from 'zod/mini'` | 158 ms | 170 ms | 175 ms | +10% |\n\n- Less severe cold start time increases from v3 to v4.\n- Still might be problematic for some users (30ms longer cold starts might be significant for some workloads)\n- `zod/mini` with tree-shaking would help reduce the bundle to only those functions actually in use.\n\n### CJS + no bundling\n\n| `zod` version | import | Init time p10 | Init time p50 | Init time p90 | p50 change vs [@3](https://github.com/3) |\n| --- | --- | --- | --- | --- | --- |\n| 3.25.76 | `const {z} = require('zod')` | 168 ms | 172 ms | 200 ms | 0% |\n| 4.0.10 | `const {z} = require('zod/v3)'` | 160 ms | 170 ms | 173 ms | -1% |\n| 4.0.10 | `const {z} = require('zod/v4)'` | 229 ms | 242 ms | 248 ms | +41% |\n| 4.0.10 | `const {z} = require('zod/mini)'` | 239 ms | 254 ms | 286 ms | +48% |\n\n- Cold start time increases by > 40% for v4 compared to v3.\n\n### CJS + `esbuild`\n\n| `zod` version | import | Init time p10 | Init time p50 | Init time p90 | p50 change vs [@3](https://github.com/3) |\n| --- | --- | --- | --- | --- | --- |\n| 3.25.76 | `const {z} = require('zod')` | 149 ms | 158 ms | 166 ms | 0% |\n| 4.0.10 | `const {z} = require('zod/v3)'` | 151 ms | 160 ms | 179 ms | +1% |\n| 4.0.10 | `const {z} = require('zod/v4)'` | 197 ms | 210 ms | 219 ms | +33% |\n| 4.0.10 | `const {z} = require('zod/mini)'` | 188 ms | 196 ms | 214 ms | +24% |\n\n- Cold start time increase is still significant though reduced from the \"unbundled\" version above.\n\n## Thoughts / summary\n\n- These experiments show that the Lambda cold-start time does increase significantly from v3 to v4 of `zod` (between 10% and 50% depending on the module system / bundling strategy).\n- All of the \"unbundled\" Lambda zip files were extremely similar sizes in terms of file size — the difference in init time is purely down to the amount of JS code that is parsed / executed during startup.\n- The results are broadly repeatable (which can be seen from the consistent results between `zod@3` and importing `zod/v3` from `zod@4`)\n- Whether the maintainers of `zod` choose to address this is totally up to them though I strongly suspect we will use a different library if it isn't.\n\n😕React with 😕1manu-remsense\n\n[inkeep-ai-assistant](https://github.com/apps/inkeep-ai-assistant)\n\nmentioned this [on Sep 6, 2025on Sep 6, 2025](https://github.com/colinhacks/zod/issues/4637#event-3230322256)\n\n- [\\[Zod 4\\]: Big size import start form 49.8Kb gzip #5206](https://github.com/colinhacks/zod/issues/5206)\n\n\n[irvinebroque](https://github.com/irvinebroque)\n\nmentioned this [on Oct 6, 2025on Oct 6, 2025](https://github.com/colinhacks/zod/issues/4637#event-3543634779)\n\n- [Replace imports of Zod with wildcard import cloudflare/agents#537](https://github.com/cloudflare/agents/pull/537)\n\n\n[gr2m](https://github.com/gr2m)\n\nmentioned this [on Oct 8, 2025on Oct 8, 2025](https://github.com/colinhacks/zod/issues/4637#event-3562504450)\n\n- [CI: add bundle size and benchmark monitoring vercel/ai#9287](https://github.com/vercel/ai/issues/9287)\n\n\n[dosubot](https://github.com/apps/dosubot)\n\nmentioned this [on Dec 22, 2025on Dec 22, 2025](https://github.com/colinhacks/zod/issues/4637#event-4189599925)\n\n- [Zod Mini - Tree shaking not removing locales #5561](https://github.com/colinhacks/zod/issues/5561)\n\n\n[DoroGi](https://github.com/DoroGi)\n\nmentioned this in 2 issues [on Jan 16on Jan 16, 2026](https://github.com/colinhacks/zod/issues/4637#event-4388350875)\n\n- [Next does not tree-shake Zod correctly vercel/next.js#88643](https://github.com/vercel/next.js/issues/88643)\n\n- [zod/mini is still not tree-shaken correctly inside NextJS #5641](https://github.com/colinhacks/zod/issues/5641)\n\n\n[Sign up for free](https://github.com/signup?return_to=https://github.com/colinhacks/zod/issues/4637)**to join this conversation on GitHub.** Already have an account? [Sign in to comment](https://github.com/login?return_to=https://github.com/colinhacks/zod/issues/4637)\n\n## Metadata\n\n## Metadata\n\n### Assignees\n\nNo one assigned\n\n### Labels\n\nNo labels\n\nNo labels\n\n### Projects\n\nNo projects\n\n### Milestone\n\nNo milestone\n\n### Relationships\n\nNone yet\n\n### Development\n\nCode with agent mode\n\nSelect code repository\n\nNo branches or pull requests\n\n### Participants\n\n[](https://github.com/colinhacks)[](https://github.com/paulbrimicombe)\n\n## Issue actions\n\nYou can’t perform that action at this time.","metadata":{"twitter:image":"https://opengraph.githubassets.com/8b3b5c958cee472f027ca7c4e6929ee2d72e5a65710c77de2f54e1e409d4e18e/colinhacks/zod","og:type":"object","expected-hostname":"github.com","og:url":"https://github.com/colinhacks/zod","request-id":"1C21:3BA896:4102290:535BAE0:69C90B34","twitter:card":"summary_large_image","analytics-location":"/<user-name>/<repo-name>/issues/show","octolytics-dimension-repository_network_root_id":"245704608","ogTitle":"colinhacks/zod","fetch-nonce":"v2:f332c27d-ce2f-7dce-3161-d2ab9d61de84","og:image:alt":"TypeScript-first schema validation with static type inference - colinhacks/zod","turbo-body-classes":"logged-out env-production page-responsive","fb:app_id":"1401488693436528","disable-turbo":"false","visitor-hmac":"20f1e00ab70ef8c5ff81c78727ba7511a130a527a1ec8e1679d355cbde424068","ogSiteName":"GitHub","og:image:width":"1200","html-safe-nonce":"f24bc6e0b1d94c1b81cbf716f718dfbdd851c8a9b1dd6abc5e681f16755c2329","og:site_name":"GitHub","octolytics-dimension-repository_is_fork":"false","title":"4x bundle size increase with CommonJS for v4 and v4-mini vs v3 · Issue #4637 · colinhacks/zod","go-import":"github.com/colinhacks/zod git https://github.com/colinhacks/zod.git","apple-itunes-app":"app-id=1477376905, app-argument=https://github.com/colinhacks/zod/issues/4637","viewport":"width=device-width","theme-color":"#1e2327","og:image":"https://opengraph.githubassets.com/8b3b5c958cee472f027ca7c4e6929ee2d72e5a65710c77de2f54e1e409d4e18e/colinhacks/zod","turbo-cache-control":["no-preview","no-cache"],"ogDescription":"TypeScript-first schema validation with static type inference - colinhacks/zod","og:description":"TypeScript-first schema validation with static type inference - colinhacks/zod","visitor-payload":"eyJyZWZlcnJlciI6Imh0dHBzOi8vd3d3Lmdvb2dsZS5jb20vIiwicmVxdWVzdF9pZCI6IjFDMjE6M0JBODk2OjQxMDIyOTA6NTM1QkFFMDo2OUM5MEIzNCIsInZpc2l0b3JfaWQiOiI3Nzc1Njk0NzA2Njg0MDA1MTcyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=","octolytics-dimension-user_id":"3084745","language":"en","ogUrl":"https://github.com/colinhacks/zod","octolytics-dimension-repository_public":"true","twitter:site":"@github","octolytics-url":"https://collector.github.com/github/collect","octolytics-dimension-repository_network_root_nwo":"colinhacks/zod","google-site-verification":"Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I","twitter:description":"TypeScript-first schema validation with static type inference - colinhacks/zod","route-pattern":"/:user_id/:repository/issues/:id(.:format)","browser-errors-url":"https://api.github.com/_private/browser/errors","twitter:title":"colinhacks/zod","ogImage":"https://opengraph.githubassets.com/8b3b5c958cee472f027ca7c4e6929ee2d72e5a65710c77de2f54e1e409d4e18e/colinhacks/zod","hostname":"github.com","ui-target":"full","route-controller":"issues","octolytics-dimension-user_login":"colinhacks","user-login":"","hovercard-subject-tag":"repository:245704608","release":"51d2e33e3d1e4839c3ced5f8e35c7a47d3a60f32","octolytics-dimension-repository_id":"245704608","octolytics-dimension-repository_nwo":"colinhacks/zod","github-keyboard-shortcuts":"repository,issues,copilot","og:title":"colinhacks/zod","route-action":"show","description":"TypeScript-first schema validation with static type inference - colinhacks/zod","og:image:height":"600","color-scheme":"light dark","browser-stats-url":"https://api.github.com/_private/browser/stats","current-catalog-service-hash":"81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114","favicon":"https://github.githubassets.com/favicons/favicon.svg","scrapeId":"019d3953-c386-760f-971d-e4926766ee83","sourceURL":"https://github.com/colinhacks/zod/issues/4637","url":"https://github.com/colinhacks/zod/issues/4637","statusCode":200,"contentType":"text/html; charset=utf-8","timezone":"America/New_York","proxyUsed":"basic","cacheState":"miss","indexId":"c7a7000c-0f2d-4a0b-a0ff-1a72fcefa9aa","creditsUsed":1}},{"url":"https://dev.to/wildboar_developer/introducing-zod-4-super-fast-lightweight-and-packed-with-powerful-features-4fkg","title":"Introducing Zod 4 – Super Fast, Lightweight, and Packed with ...","description":"Core bundle size is 2.3x smaller than Zod 3, making your applications lighter and faster to load. The zod/v4-mini variant is even lighter (~1.88 ...","position":4,"markdown":"After a year of active development, Zod 4 is officially released with major improvements. This stable version is faster, slimmer, and more TypeScript-optimized compared to the previous Zod 3.\n\n## Highlights of Zod 4\n\n### 🚀 Outstanding Performance\n\n- **14x faster string parsing:** Deep optimizations in string validation make your app respond much faster, especially when handling large amounts of text data.\n\n- **7x faster array parsing:** Efficiently process complex or large arrays, minimizing latency in data validation.\n\n- **6.5x faster object parsing:** Ideal for objects with many fields, ensuring smoother validation and faster API responses.\n\n### ⚡ TypeScript Compiler Optimization\n\n- Reduces type instantiations by up to **100x**, speeding up the TypeScript compiler significantly, especially for large and complex codebases.\n\n- Compilation time is improved by around **10x** compared to Zod 3, providing a smoother developer experience and faster editor feedback.\n\n### 📦 Reduced Bundle Size\n\n- Core bundle size is **2.3x smaller** than Zod 3, making your applications lighter and faster to load.\n\n- The `zod/v4-mini` variant is even lighter (~1.88KB gzip), using a functional API optimized for **tree-shaking**, perfect for projects with strict bundle size limits.\n\n### 🏷️ Powerful Metadata System\n\n- Allows attaching strongly-typed metadata to schemas, enabling easy mapping to standard JSON Schema.\n\n- Great for automation tools, API documentation, and data transformation workflows.\n\n### 🔄 Simple Recursive and Mutually Recursive Types\n\n- Define self-referencing or mutually referencing types (e.g., category trees, user-post relationships) directly without complex casting hacks.\n\n- Increases code clarity and maintainability.\n\n### 🌐 Internationalized Error API\n\n- Supports a **locales** system to translate error messages into multiple languages, improving user experience in global applications.\n\n- English locale available now, with community contributions expected for more languages.\n\n### ✨ New Top-Level String Format APIs\n\n- Popular formats like `email()`, `uuid()`, `ip()`, and `url()` are now top-level functions, leading to cleaner code and better tree-shaking.\n\n- Older method-based APIs on strings remain available but are deprecated.\n\n### 🔤 `z.stringbool()`\n\n- Converts strings to booleans using a flexible, environment-variable style (e.g., `\"true\"`, `\"yes\"`, `\"1\"` → `true`; `\"false\"`, `\"no\"`, `\"0\"` → `false`).\n\n- Customizable truthy/falsy values to fit your specific needs, making it easy to validate boolean-like string inputs.\n\n### 🎯 Simplified Error Customization API\n\n- Unifies various error customization approaches into a single `error` parameter, which can be a string or function, enabling concise and clear error definitions.\n\n- Reduces complexity and confusion when writing validations and handling errors.\n\n### 🔀 More Powerful Discriminated Unions\n\n- Supports multiple schema types as discriminators, including unions, pipes, and nested objects.\n\n- Allows creating complex and maintainable type classifications for diverse data structures.\n\n### 🔧 `.overwrite()` Method\n\n- Alternative to `.transform()` for applying data transformations **without changing the inferred type**, preserving type information.\n\n- Useful for simple data manipulation without breaking compatibility with JSON Schema or inferred types.\n\n### 🧩 Zod Mini\n\n- A **super lightweight** functional API variant that removes excess methods to optimize tree-shaking, resulting in very small final bundles.\n\n- Perfect for front-end apps needing minimal download sizes while still using Zod for validation.\n\n### 🚀 Conclusion\n\nZod 4 marks a significant advancement in TypeScript schema validation, offering enhanced performance, reduced bundle sizes, and a more intuitive API. With features like improved TypeScript compiler efficiency, a powerful metadata system, and streamlined error handling, Zod 4 is designed to meet the needs of modern development.\n\nFor comprehensive documentation, including guides on defining schemas, customizing errors, and integrating with JSON Schema, visit the official Zod 4 documentation: [https://zod.dev/v4](https://zod.dev/v4).\n\nHappy coding! 😊\n\n[\\\\\nMongoDB](https://dev.to/mongodb) Promoted\n\nDropdown menu\n\n- [What's a billboard?](https://dev.to/billboards)\n- [Manage preferences](https://dev.to/settings/customization#sponsors)\n\n* * *\n\n- [Report billboard](https://dev.to/report-abuse?billboard=241243)\n\n[](https://www.mongodb.com/cloud/atlas/lp/try3?utm_campaign=display_devto-broad_pl_flighted_atlas_tryatlaslp_prosp_gic-null_ww-all_dev_dv-all_eng_leadgen&utm_source=devto&utm_medium=display&utm_content=runappsanywhere-v1&bb=241243)\n\n## [Build seamlessly, securely, and flexibly with MongoDB Atlas. Try free.](https://www.mongodb.com/cloud/atlas/lp/try3?utm_campaign=display_devto-broad_pl_flighted_atlas_tryatlaslp_prosp_gic-null_ww-all_dev_dv-all_eng_leadgen&utm_source=devto&utm_medium=display&utm_content=runappsanywhere-v1&bb=241243)\n\nMongoDB Atlas lets you build and run modern apps in 125+ regions across AWS, Azure, and Google Cloud. Multi-cloud clusters distribute data seamlessly and auto-failover between providers for high availability and flexibility. Start free!\n\n[Learn More](https://www.mongodb.com/cloud/atlas/lp/try3?utm_campaign=display_devto-broad_pl_flighted_atlas_tryatlaslp_prosp_gic-null_ww-all_dev_dv-all_eng_leadgen&utm_source=devto&utm_medium=display&utm_content=runappsanywhere-v1&bb=241243)\n\nRead More\n\n\n\n\n[Create template](https://dev.to/settings/response-templates)\n\nTemplates let you quickly answer FAQs or store snippets for re-use.\n\nSubmitPreview [Dismiss](https://dev.to/404.html)\n\nAre you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's [permalink](https://dev.to/wildboar_developer/introducing-zod-4-super-fast-lightweight-and-packed-with-powerful-features-4fkg#).\n\n\nHide child comments as well\n\nConfirm\n\n\nFor further actions, you may consider blocking this person and/or [reporting abuse](https://dev.to/report-abuse)\n\n[\\\\\nDraft.dev](https://dev.to/draft) Promoted\n\nDropdown menu\n\n- [What's a billboard?](https://dev.to/billboards)\n- [Manage preferences](https://dev.to/settings/customization#sponsors)\n\n* * *\n\n- [Report billboard](https://dev.to/report-abuse?billboard=261775)\n\n[](https://graphite.com/l/stacked-prs-guide?utm_source=draft-dev&bb=261775)\n\n## [Stop Shipping Massive PRs](https://graphite.com/l/stacked-prs-guide?utm_source=draft-dev&bb=261775)\n\nBig pull requests slow everything down. This guide explains stacked pull requests and shows how to roll them out without breaking your workflow or starting a Git rebase war. Written for engineering managers who just want reviews to move faster.\n\n[Read more](https://graphite.com/l/stacked-prs-guide?utm_source=draft-dev&bb=261775)\n\n👋 Kindness is contagious\n\nDropdown menu\n\n- [What's a billboard?](https://dev.to/billboards)\n- [Manage preferences](https://dev.to/settings/customization#sponsors)\n\n* * *\n\n- [Report billboard](https://dev.to/report-abuse?billboard=239375)\n\nx\n\n**Sign in** to DEV to enjoy its full potential.\n\nUnlock a **customized** interface with dark mode, personal reading preferences, and more.\n\n### [Okay](https://dev.to/enter?state=new-user&bb=239375)\n\n\n\nWe're a place where coders share, stay up-to-date and grow their careers.\n\n\n[Log in](https://dev.to/enter?signup_subforem=1) [Create account](https://dev.to/enter?signup_subforem=1&state=new-user)\n\n","metadata":{"og:site_name":"DEV Community","robots":"max-snippet:-1, max-image-preview:large, max-video-preview:-1","twitter:description":"After a year of active development, Zod 4 is officially released with major improvements. This stable...","head-cached-at":"1774706361","description":"After a year of active development, Zod 4 is officially released with major improvements. This stable... Tagged with news, javascript, learning.","ogImage":"https://media2.dev.to/dynamic/image/width=1000,height=500,fit=cover,gravity=auto,format=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feeqnth9bmhj47l902d41.png","twitter:card":"summary_large_image","ogDescription":"After a year of active development, Zod 4 is officially released with major improvements. This stable...","og:title":"Introducing Zod 4 – Super Fast, Lightweight, and Packed with Powerful Features!","language":"en","og:description":"After a year of active development, Zod 4 is officially released with major improvements. This stable...","ogSiteName":"DEV Community","twitter:creator":"@","og:image":"https://media2.dev.to/dynamic/image/width=1000,height=500,fit=cover,gravity=auto,format=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feeqnth9bmhj47l902d41.png","twitter:widgets:new-embed-design":"on","twitter:image:src":"https://media2.dev.to/dynamic/image/width=1000,height=500,fit=cover,gravity=auto,format=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feeqnth9bmhj47l902d41.png","last-updated":"2026-03-28 13:59:21 UTC","forem:domain":"dev.to","csrf-param":"authenticity_token","og:type":"article","title":"Introducing Zod 4 – Super Fast, Lightweight, and Packed with Powerful Features! - DEV Community","ogTitle":"Introducing Zod 4 – Super Fast, Lightweight, and Packed with Powerful Features!","theme-color":["#ffffff","#000000"],"user-signed-in":"false","viewport":"width=device-width, initial-scale=1.0, viewport-fit=cover","application-name":"dev.to","og:url":"https://dev.to/wildboar_developer/introducing-zod-4-super-fast-lightweight-and-packed-with-powerful-features-4fkg","environment":"production","forem:name":"DEV Community","keywords":"news, javascript, learning, software, coding, development, engineering, inclusive, community","twitter:site":"@thepracticaldev","twitter:title":"Introducing Zod 4 – Super Fast, Lightweight, and Packed with Powerful Features!","csrf-token":"isAvqzUIkoND3kUpLhtoATWIFgdObedkimbmPVDt8OQ4w3Z_XmoAuDfYiVVGQtkpY2rJdF1kQ7ksBGaoDOZYzw","forem:logo":"https://media2.dev.to/dynamic/image/width=512,height=,fit=scale-down,gravity=auto,format=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8j7kvp660rqzt99zui8e.png","ogUrl":"https://dev.to/wildboar_developer/introducing-zod-4-super-fast-lightweight-and-packed-with-powerful-features-4fkg","apple-mobile-web-app-title":"dev.to","search-script":"https://assets.dev.to/assets/Search-b977aea0f2d7a5818b4ebd97f7d4aba8548099f84f5db5761f8fa67be76abc54.js","favicon":"https://media2.dev.to/dynamic/image/width=32,height=,fit=scale-down,gravity=auto,format=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8j7kvp660rqzt99zui8e.png","scrapeId":"019d3953-c386-760f-971d-e9db278980f0","sourceURL":"https://dev.to/wildboar_developer/introducing-zod-4-super-fast-lightweight-and-packed-with-powerful-features-4fkg","url":"https://dev.to/wildboar_developer/introducing-zod-4-super-fast-lightweight-and-packed-with-powerful-features-4fkg","statusCode":200,"contentType":"text/html; charset=utf-8","timezone":"America/New_York","proxyUsed":"basic","cacheState":"miss","indexId":"d8bae458-a253-48f8-9991-dd0f4eb4ba2c","creditsUsed":1}},{"url":"https://www.infoq.com/news/2025/08/zod-v4-available/","title":"Zod v4 Available with Major Performance Improvements and ... - InfoQ","description":"Another headline feature in this release is the introduction of @zod/mini, a lightweight distribution weighing just ~1.9 KB gzipped, designed ...","position":5,"markdown":"[BT](https://www.infoq.com/int/bt/ \"bt\")\n\n## InfoQ Software Architects' Newsletter\n\nA monthly overview of things you need to know as an architect or aspiring architect.\n\n[View an example](https://www.infoq.com/software-architects-newsletter#placeholderPastIssues)\n\nEnter your e-mail address\n\nSelect your countrySelect a countryAfghanistanÅlandAlbaniaAlgeriaAmerican SamoaAndorraAngolaAnguillaAntarcticaAntigua and BarbudaArgentinaArmeniaArubaAustraliaAustriaAzerbaijanBahamasBahrainBangladeshBarbadosBelarusBelgiumBelizeBeninBermudaBhutanBoliviaBonaire, Sint Eustatius, and SabaBosnia and HerzegovinaBotswanaBouvet IslandBrazilBritish Indian Ocean TerritoryBrunei DarussalamBulgariaBurkina FasoBurundiCambodiaCameroonCanadaCape VerdeCayman IslandsCentral African RepublicChadChileChinaChristmas IslandCocos (Keeling) IslandsColombiaComorosCongo (Democratic Republic)Congo (People's Republic)Cook IslandsCosta RicaCote D'IvoireCroatiaCubaCuraçaoCyprusCzech RepublicDenmarkDjiboutiDominicaDominican RepublicEast TimorEcuadorEgyptEl SalvadorEquatorial GuineaEritreaEstoniaEthiopiaFalkland Islands (Malvinas)Faroe IslandsFijiFinlandFranceFrench GuianaFrench PolynesiaFrench Southern TerritoriesGabonGambiaGeorgiaGermanyGhanaGibraltarGreeceGreenlandGrenadaGuadeloupeGuamGuatemalaGuernseyGuineaGuinea-BissauGuyanaHaitiHeard Island and McDonald IslandsHondurasHong KongHungaryIcelandIndiaIndonesiaIranIraqIrelandIsle of ManIsraelItalyJamaicaJapanJerseyJordanKazakhstanKenyaKiribatiKosovoKuwaitKyrgyzstanLaosLatviaLebanonLesothoLiberiaLibyaLiechtensteinLithuaniaLuxembourgMacauMacedoniaMadagascarMalawiMalaysiaMaldivesMaliMaltaMarshall IslandsMartiniqueMauritaniaMauritiusMayotteMexicoMicronesiaMoldovaMonacoMongoliaMontenegroMontserratMoroccoMozambiqueMyanmarNamibiaNauruNepalNetherlandsNetherlands AntillesNew CaledoniaNew ZealandNicaraguaNigerNigeriaNiueNorfolk IslandNorth KoreaNorthern Mariana IslandsNorwayOmanPakistanPalauPalestinian TerritoryPanamaPapua New GuineaParaguayPeruPhilippinesPitcairnPolandPortugalPuerto RicoQatarReunionRomaniaRussian FederationRwandaSaint HelenaSaint Kitts and NevisSaint LuciaSaint MartinSaint Pierre and MiquelonSaint Vincent and the GrenadinesSaint-BarthélemySamoaSan MarinoSao Tome and PrincipeSaudi ArabiaSenegalSerbiaSeychellesSierra LeoneSingaporeSint MaartenSlovakiaSloveniaSolomon IslandsSomaliaSouth AfricaSouth Georgia and the South Sandwich IslandsSouth KoreaSouth SudanSpainSri LankaSudanSurinameSvalbard and Jan MayenSwazilandSwedenSwitzerlandSyriaTaiwanTajikistanTanzaniaThailandTogoTokelauTongaTrinidad and TobagoTunisiaTurkeyTurkmenistanTurks and Caicos IslandsTuvaluUgandaUkraineUnited Arab EmiratesUnited KingdomUnited States Minor Outlying IslandsUruguayUSAUzbekistanVanuatuVatican City (Holy See)VenezuelaVietnamVirgin Islands (British)Virgin Islands (U.S.)Wallis and FutunaWestern SaharaYemenZaireZambiaZimbabwe\n\nI consent to InfoQ.com handling my data as explained in this [Privacy Notice](https://www.infoq.com/privacy-notice).\n\n[We protect your privacy.](https://www.infoq.com/privacy-notice/)\n\nClose\n\nLive Webinar and Q&A: Portable by Design: Data Mobility & Recovery Patterns for Multi-Cloud Systems (May 21, 2026) [Save Your Seat](https://www.infoq.com/url/pb/636fe2ee-466c-4b54-affd-c6007cf3dc9d/)\n\nClose\n\n\n[InfoQ Homepage](https://www.infoq.com/ \"InfoQ Homepage\")[News](https://www.infoq.com/news \"News\")Zod v4 Available with Major Performance Improvements and Introduction of Zod Mini\n\n[Web Development](https://www.infoq.com/Web-Development/ \"Web Development\")\n\n[QCon San Francisco (Nov 16-20): Deep technical sessions. Peer conversations that change how you think.](https://qconsf.com/?utm_source=infoq&utm_medium=referral&utm_campaign=infoqyellowbox_qsf26)\n\n# Zod v4 Available with Major Performance Improvements and Introduction of Zod Mini\n\nAug 23, 2025\n\n\n\n\n2\nmin read\n\n\n\n#### Write for InfoQ\n\n**Feed your curiosity.** Help 550k+ global\n\nsenior developers\n\neach month stay ahead. [Get in touch](https://docs.google.com/forms/d/e/1FAIpQLSehsV5jwuXFRFPIoOQoSXm9aRjYam9bQjKbEHvGZBxsioyGGw/viewform)\n\nLog in to listen to this article\n\nLoading audio\n\nYour browser does not support the audio element.\n\n\n0:00\n\n0:00\n\nNormal1.25x1.5x\n\nLike\n\n- [Reading list](https://www.infoq.com/showbookmarks.action)\n\n[Zod](https://zod.dev/v4), the TypeScript-first schema validation library, has released version 4 as a stable milestone. The new version delivers performance improvements, reduced bundle size, and updated API including a new simplified, tree-shakable mini package.\n\nZod v4 introduces a series of changes across three key areas: performance, API design, and tooling support. Benchmarks published by the maintainers show [14x faster string parsing](https://zod.dev/v4#14x-faster-string-parsing), [7x faster array parsing](https://zod.dev/v4?id=7x-faster-array-parsing), and [6.5x faster object parsing](https://zod.dev/v4?id=65x-faster-object-parsing) compared to Zod 3. These improvements are paired with reductions in TypeScript type instantiation, helping projects compile faster in large codebases.\n\nAnother headline feature in this release is the introduction of [@zod/mini](https://zod.dev/v4?id=65x-faster-object-parsing#introducing-zod-mini), a lightweight distribution weighing just ~1.9 KB gzipped, designed for tree-shakable validation in modern frontend applications. One of the core advantages to Zod Mini appears to be the ability for it to tree-shake, which was difficult with the regular version of Zod. To enable this, Zod Mini generally uses wrapper functions instead of methods, so in regular Zod, a developer might use:\n\n```typescript\nimport * as z from \"zod\";\n\nz.string().optional();\n```\n\nWhereas in Zod Mini, the same functionality is achieved using a wrapper function:\n\n```typescript\nimport * as z from \"zod/mini\";\n\nz.optional(z.string());\n```\n\nThe mini library is around 6x smaller than the standard Zod v4 package.\n\nAPI refinements also feature prominently in Zod v4. Format helpers such as `z.email()`, `z.uuid()`, and `z.url()` have been promoted to [top-level functions](https://zod.dev/v4?id=65x-faster-object-parsing#top-level-string-formats), replacing method calls and improving tree-shaking. Error handling has been unified under a single error parameter, replacing the previous fragmented approach (message, required\\_error, invalid\\_type\\_error).\n\nDevelopers can also now attach strongly typed metadata to schemas, enabling new workflows such as schema-driven form generation.\n\nZod v4 further introduces built-in [JSON Schema conversion](https://zod.dev/json-schema) via `.toJSONSchema()`, eliminating the need for external libraries to bridge Zod schemas into standardized formats.\n\nFor teams upgrading from v3, an unofficial codemod ( [zod-v3-to-v4](https://github.com/nicoespeon/zod-v3-to-v4)) is available to automate common migration tasks. The maintainers have also published a [migration guide](https://zod.dev/v4/changelog) detailing breaking changes and recommendations for a smoother transition.\n\nCommunity feedback has highlighted both performance and metadata as standout features. On r/reactjs, [one developer](https://www.reddit.com/r/reactjs/comments/1lpece8/generating_forms_using_the_new_zod_4_schemas/) noted:\n\n> The most exciting thing to me is the addition of custom metadata, which means Zod is now a viable schema type for form generation.\n\nIn a [video overview](https://www.youtube.com/watch?v=xcm53k0ePmY), TypeScript educator [Matt Pocock](https://x.com/mattpocockuk) emphasized that Zod v4 is not only faster but also commented particularly on the performance of TypeScript due to the lower number of TypeScript instantiations. He also discussed the introduction of @zod/mini, and that having a tree-shakable Zod is so good for the front-end.\n\nEarly adopters have expressed enthusiasm for the release. NextJS Weekly [described Zod v4](https://www.reddit.com/r/nextjs/comments/1k221c9/nextjs_weekly_84_zod_v4_jsx_over_the_wire_react) as a monster upgrade, with developers citing speed, smaller bundles, and extensibility as compelling reasons to migrate.\n\nZod is an open-source project widely adopted across TypeScript ecosystems for runtime validation, schema inference, and API contracts. To upgrade, developers can head over to the migration guide in the documentation.\n\n## About the Author\n\n[](https://www.infoq.com/profile/Daniel-Curtis/)\n\n#### **Daniel Curtis**\n\nDaniel Curtis is a UI Development Manager at Griffiths Waite, a software consultancy based in Birmingham, UK. He leads front-end engineering efforts with a strong focus on delivering innovative enterprise solutions using TypeScript across the stack. Daniel is passionate about modern web architecture, developer experience, and the use of AI to both support software delivery and solve real customer problems within products.\n\nShow moreShow less\n\n- #### Popular in Web Development\n\n\n\n - ##### [Vercel Releases JSON-Render: a Generative UI Framework for AI-Driven Interface Composition](https://www.infoq.com/news/2026/03/vercel-json-render/ \"\")\n\n - ##### [QCon London 2026: Tools That Enable the Next 1B Developers](https://www.infoq.com/news/2026/03/qcon-next-developers/ \"\")\n\n - ##### [State of JavaScript 2025: Survey Reveals a Maturing Ecosystem with TypeScript Cementing Dominance](https://www.infoq.com/news/2026/03/state-of-js-survey-2025/ \"\")\n\n - ##### [Mobile Server-Driven UI at Scale](https://www.infoq.com/presentations/mobile-server-driven-ui-scale/ \"\")\n\n - ##### [QCon London 2026: Running AI at the Edge - Running Real Workloads Directly in the Browser](https://www.infoq.com/news/2026/03/qcon-ai-at-the-edge/ \"\")\n\n\n#### Related Sponsors\n\n - ##### [Scalable Enterprise Java for the Cloud - Download the eBook](https://www.infoq.com/url/f/ad5bf784-85e1-4593-b2eb-7ead05f29ab8/)\n\n - ##### [Designing a Control Plane for Cloud Infrastructure: Governance, State, and Continuous Orchestration (Live Webinar Apr 16th) - Save Your Seat](https://www.infoq.com/vendorcontent/show.action?vcr=497186d7-52ff-4b4c-8edf-3479a4e5a331&primaryTopicId=2748&vcrPlace=BOTTOM&pageType=NEWS_PAGE&vcrReferrer=https%3A%2F%2Fwww.infoq.com%2Fnews%2F2025%2F08%2Fzod-v4-available%2F)\n\n - ##### [Portable by Design: Data Mobility & Recovery Patterns for Multi-Cloud Systems (Live Webinar May 21, 2026) - Save Your Seat](https://www.infoq.com/vendorcontent/show.action?vcr=3458336b-4af4-46e3-b96d-fa27a28e5055&primaryTopicId=2748&vcrPlace=BOTTOM&pageType=NEWS_PAGE&vcrReferrer=https%3A%2F%2Fwww.infoq.com%2Fnews%2F2025%2F08%2Fzod-v4-available%2F)\n\n - ##### [Cutting Java Costs in 2026 Without Slowing Delivery](https://www.infoq.com/vendorcontent/show.action?vcr=87743dd9-e2a2-4ef6-b20e-d99f70eadc42&primaryTopicId=2748&vcrPlace=BOTTOM&pageType=NEWS_PAGE&vcrReferrer=https%3A%2F%2Fwww.infoq.com%2Fnews%2F2025%2F08%2Fzod-v4-available%2F)\n\n - ##### [Design for Failure: How to Guarantee Data Access During Cloud Outages](https://www.infoq.com/vendorcontent/show.action?vcr=b2c4539a-b77f-4893-8169-aadb23be83b2&primaryTopicId=2748&vcrPlace=BOTTOM&pageType=NEWS_PAGE&vcrReferrer=https%3A%2F%2Fwww.infoq.com%2Fnews%2F2025%2F08%2Fzod-v4-available%2F)\n- #### Related Sponsor\n\n[/filters:no_upscale()/sponsorship/topic/5aab5793-1aa2-43a6-9086-318627c6365a/PayaraLogo-1763716038782.png)](https://www.infoq.com/url/f/a30a7dce-63d3-462b-9160-dbe2672b779e/)\n\n\n\nMove from complexity to control. Run and scale your Jakarta EE, Spring, and Quarkus applications on a unified platform that replaces infrastructure chaos with deployment simplicity and total autonomy. [**Learn More**](https://www.infoq.com/url/f/522e1507-e184-49f1-b584-c0c023dcf6f9/).\n\n\n[BT](https://www.infoq.com/int/bt/ \"bt\")","metadata":{"tprox":"1755946800000","google-site-verification":"0qInQx_1WYOeIIbxnh7DnXlw1XOxNgAYakO2k4GhNnY","og:type":"website","language":"en","ogDescription":"Zod v4, the TypeScript-first schema validation library, introduces transformative upgrades: 14x faster parsing, a 57% smaller core, and the new lightweight @zod/mini for modern front-end validation. With a refined API and built-in JSON Schema conversion, Zod v4 enhances developer efficiency while simplifying complex projects.","wb:webmaster":"3eac1729a8bbe046","og:description":"Zod v4, the TypeScript-first schema validation library, introduces transformative upgrades: 14x faster parsing, a 57% smaller core, and the new lightweight @zod/mini for modern front-end validation. With a refined API and built-in JSON Schema conversion, Zod v4 enhances developer efficiency while simplifying complex projects.","twitter:title":"Zod v4 Available with Major Performance Improvements and Introduction of Zod Mini ","og:title":"Zod v4 Available with Major Performance Improvements and Introduction of Zod Mini ","ogUrl":"https://www.infoq.com/news/2025/08/zod-v4-available/","viewport":"width=device-width,initial-scale=1","ifq:pageType":"NEWS_PAGE","description":"Zod v4, the TypeScript-first schema validation library, introduces transformative upgrades: 14x faster parsing, a 57% smaller core, and the new lightweight @zod/mini for modern front-end validation. W","copyright":"© 2006 C4Media","msapplication-TileColor":"#ffffff","msapplication-TileImage":"/styles/static/images/logo/logo.jpg","keywords":"zod v4 available,Development,React,Schema,Web Development,Front-end,TypeScript,Vue.js,Validation,Angular,JSON,","twitter:image":"https://res.infoq.com/news/2025/08/zod-v4-available/en/card_header_image/generatedCard-1755772246614.jpg","twitter:description":"Zod v4, the TypeScript-first schema validation library, introduces transformative upgrades: 14x faster parsing, a 57% smaller core, and the new lightweight @zod/mini for modern front-end validation. With a refined API and built-in JSON Schema conversion, Zod v4 enhances developer efficiency while simplifying complex projects.","og:image":"https://res.infoq.com/news/2025/08/zod-v4-available/en/headerimage/generatedHeaderImage-1755772246614.jpg","og:site_name":"InfoQ","title":"Zod v4 Available with Major Performance Improvements and Introduction of Zod Mini - InfoQ","ogSiteName":"InfoQ","twitter:card":"summary_large_image","ogTitle":"Zod v4 Available with Major Performance Improvements and Introduction of Zod Mini ","og:url":"https://www.infoq.com/news/2025/08/zod-v4-available/","ogImage":"https://res.infoq.com/news/2025/08/zod-v4-available/en/headerimage/generatedHeaderImage-1755772246614.jpg","favicon":"https://cdn.infoq.com/statics_s2_20260319113822/favicon.ico","scrapeId":"019d3953-c386-760f-971d-eebad413259e","sourceURL":"https://www.infoq.com/news/2025/08/zod-v4-available/","url":"https://www.infoq.com/news/2025/08/zod-v4-available/","statusCode":200,"contentType":"text/html;charset=utf-8","timezone":"America/New_York","proxyUsed":"basic","cacheState":"miss","indexId":"1badeeeb-aa90-49b6-bb1b-bd3083a5ace8","creditsUsed":1}}]}} |