Skip to content

zod 4.5.4 costs ~15.6 KiB of bundle, leaving ~9 KiB of budget headroom #370

Closed

Description

@CameronBrooks11

Merging #361 / #363 raises the GUI JS bundle from 321.05 KiB → 337.4 KiB, against a budget of 346.62 KiB. It passes, but headroom drops from ~25 KiB to ~9 KiB, so the next moderate dependency bump is likely to trip perf:bundle.

Attribution

Measured on the #361 branch, changing one package at a time and rebuilding:

Configuration JS Δ
branch as-is (svelte 5.57.0, zod 4.5.4) 337.43 KiB —
svelte pinned back to 5.56.9 336.63 KiB −0.80 KiB
zod pinned back to 4.4.3 321.85 KiB −15.58 KiB

So essentially all of the growth is zod 4.4.3 → 4.5.4; svelte 5.57.0 costs under a kilobyte.

Why this is worth a decision

The budget is doing its job — it made an invisible 5% bundle growth visible. But the response shouldn't be to raise the number reflexively. Options, roughly in order of preference:

  1. Check whether zod is fully tree-shaken. src/lib/schemas.ts uses a small surface (z.object, z.number, z.literal, .nullish, .optional). If v4.5 regressed tree-shaking, that is worth an upstream look.
  2. Consider zod/mini, which exists for exactly this and keeps the same validation semantics for this schema shape.
  3. Raise the budget deliberately, recording why.

Reproduce

cd fiberpath_gui && npm ci && npm run build && npm run perf:bundle

Found while reviewing #361/#363 before merge; neither PR is blocked by this.

Activity

  1. added
    enhancement
    dependencies
    gui
    on Sep 8, 2026
  2. CameronBrooks11 commented on Sep 10, 2026

    @CameronBrooks11
    MemberAuthor

    Measured it, and the framing in this issue is too narrow

    I attributed real minified bytes per module by decoding the build's sourcemap mappings (not source sizes, which overstate large libraries):

    module minified share of bundle
    ajv 101.0 KiB 30.3%
    zod 80.8 KiB 24.2%
    app source 75.6 KiB 22.7%
    svelte 48.6 KiB 14.6%
    fast-uri (ajv dep) 16.0 KiB 4.8%
    openapi-fetch 6.4 KiB 1.9%

    Total attributed: 333.4 KiB.

    The app ships two independent validation stacks that together are ~60% of its JavaScript. ajv + fast-uri + json-schema-traverse + fast-deep-equal is ~118 KiB; zod is another ~81 KiB.

    The zod 4.4.3 → 4.5.4 growth this issue was opened for (+15.6 KiB) is real, but it is a symptom. And notably ajv is the larger of the two, so zod/mini — the obvious fix — targets the smaller half.

    They validate the same contract

    • src/lib/validation.ts (ajv) compiles schemas/wind-schema.json, which is generated from the Pydantic models. Callers: HelicalLayerEditor.svelte, project-session, preview-session.
    • src/lib/schemas.ts (zod) hand-mirrors the same .wind shapes in TypeScript. Callers: file-operations.svelte.ts (open/save gate), backend-health.svelte.ts.

    So the .wind contract is expressed twice: once authoritatively as generated JSON Schema, once by hand in zod. That is a drift risk, not just weight — and it has already bitten once. From #345's commit message:

    #352 added frictionLambda to the Zod gate for validation parity but never threaded it through the converters, a latent silent-strip masked only by that guard.

    Worth noting src/types/wind-schema.ts already exists, generated from the same JSON Schema by json-schema-to-typescript — so the types zod provides are available without zod.

    Also found

    ajv is imported by src/lib/validation.ts, which is runtime application code, but it is declared in devDependencies. It works because Vite bundles it, so this is a declaration bug rather than a live fault.

    Recommendation

    Reframe this issue from "zod got bigger" to "the GUI carries two validators for one contract". Collapsing onto the generated JSON Schema (ajv) plus the already-generated TS types would remove ~81 KiB and delete the hand-maintained mirror that can drift. Dropping ajv instead would save more (~118 KiB) but would give up validation against the authoritative schema, so it is the worse trade.

    This is an architecture decision rather than a dependency tweak, so I have not acted on it.

  3. added a commit that references this issue on Sep 10, 2026
    ed9015c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    dependenciesenhancementgui

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions