Skip to main content

bundle size Kanon Bundle Size

Real numbers. No marketing fluff. Data auto-generated on Feb 27, 2026.

TL;DR

For a complete app with all schema types (gzip):

  • Kanon : 4.19 kB baseline
  • Zod 4 Mini : 9.57 kB (+128%)
  • Zod 4 Classic : 17.24 kB (+311%)

Real-World Use Cases

These are actual validation scenarios you'll encounter in production:

Use CaseKanon v3Zod 4 MiniZod 4 ClassicZod 3
Login Form
Login form validation
3.06 kB
baseline
6.71 kB
+119%
14.72 kB
+381%
12.80 kB
+318%
User Profile
User profile with optional fields
3.40 kB
baseline
7.53 kB
+121%
15.88 kB
+367%
12.84 kB
+277%
API Response
API response with discriminated union
3.44 kB
baseline
7.00 kB
+103%
15.96 kB
+364%
12.82 kB
+272%
Config Validation
App configuration validation
3.23 kB
baseline
7.35 kB
+128%
15.90 kB
+393%
12.86 kB
+298%
Form + Coercion
Form data with type coercion
3.20 kB
baseline
6.91 kB
+116%
16.14 kB
+405%
12.88 kB
+303%
Full App
Complete app schemas (comprehensive)
4.19 kB
baseline
9.57 kB
+128%
17.24 kB
+311%
13.06 kB
+211%
Data generated on Feb 27, 2026 • Measured with esbuild + gzip

What each test validates

Use CaseWhat it validates
Login FormEmail + password with constraints
User ProfileUUID, email, optional age, roles array
API ResponseDiscriminated union (success/error)
Config ValidationURL, port range, enum, optional timeout
Form + CoercionString→Number, String→Boolean, String→Date
Full AppEverything above + discriminatedUnion, record, etc.

Kanon Detailed Breakdown

Use CaseRawGzipBrotli
Login Form
Login form validation
10.38 kB3.06 kB2.71 kB
User Profile
User profile with optional fields
11.65 kB3.40 kB3.00 kB
API Response
API response with discriminated union
11.81 kB3.44 kB3.03 kB
Config Validation
App configuration validation
10.81 kB3.23 kB2.85 kB
Form + Coercion
Form data with type coercion
11.08 kB3.20 kB2.84 kB
Full App
Complete app schemas (comprehensive)
14.44 kB4.19 kB3.72 kB

Data generated on Feb 27, 2026


Why Kanon is Smaller: True Tree-Shaking

Kanon uses pure functions. Zod uses classes. This architectural difference is why Kanon tree-shakes perfectly.

// ✅ Kanon - each function is standalone
// Only string() and object() end up in your bundle
import { string, object, parse } from "pithos/kanon";

const loginSchema = object({
email: string({ format: "email" }),
password: string({ minLength: 8 }),
});
// ⚠️ Zod - z is a namespace that carries ALL methods
// The entire Zod library ends up in your bundle
import { z } from "zod";

const loginSchema = z.object({
email: z.string().email(),
password: z.string().min(8),
});

Even z.string().min(1) pulls in ~15 kB because class methods are bundled together.

Zod 4 Mini: A Partial Solution

Zod 4 introduced zod/mini which is smaller, but still can't fully tree-shake:

ScenarioZod 4 ClassicZod 4 MiniKanon v3
Simple login form~14.7 kB~6.7 kB~3.1 kB
Full app schemas~17.2 kB~9.6 kB~4.2 kB
Growth rate+17%+43%+37%

Kanon v2.0.1 vs Zod v4.3.5

Kanon's bundle grows proportionally with usage. Zod's is mostly fixed overhead.


Convenience Helpers: k, z & validation

Kanon offers convenience helpers for different use cases, but they come with a trade-off:

Import StyleKanon v3Zod 4 MiniZod 4 Classic
Direct imports
Always (production)
3.06 kB
baseline
6.71 kB
+119%
14.72 kB
+381%
validation helper +3%
validation(schema).safeParse(data)
3.14 kB
baseline
6.71 kB
+114%
14.72 kB
+369%
k namespace +74%
Zod-like syntax: k.string(), k.object()...
5.32 kB
baseline
6.71 kB
+26%
14.72 kB
+177%
z shim +119%
Migrating from Zod
6.71 kB
baseline
6.71 kB
+-0%
14.72 kB
+119%
Kanon baseline: Login Form with direct imports

Reproduce These Results

Want to verify these results? See how to reproduce our data.


Summary

AspectKanonZod
ArchitectureFunctionsClasses
Tree-shaking✅ Full❌ Limited
Min bundle~3 kB~7-15 kB
Scales with usage✅ Yes❌ Mostly fixed
Migration pathz shim availableN/A
Bottom line

In production: Use direct imports for the smallest bundle.
Prototyping: Use k namespace for convenience.
Migrating from Zod: Use z shim, then gradually switch to direct imports.


Related