Skip to content

Upgrade zod to 4.5.2 and use compile() on hot-path schemas - #13

Merged
Jbithell merged 1 commit into
mainfrom
claude/zod-upgrade-compile-laqlve
Aug 29, 2026
Merged

Upgrade zod to 4.5.2 and use compile() on hot-path schemas#13
Jbithell merged 1 commit into
mainfrom
claude/zod-upgrade-compile-laqlve

Conversation

@Jbithell

Copy link
Copy Markdown
Collaborator

Summary

  • Bump zod from 4.4.3 to 4.5.2 in website/package.json (see the 4.5 memory-footprint post — lazy method memoization reduces per-schema memory overhead automatically, no code changes needed for that part).
  • Wrap the finalized schemas in z.compile() where it can actually take effect: website/app/logbook/config.ts (logbookConfigSchema, which is parsed per device/day when building logbooks) and website/app/routes/api/{flespiUpload,traccarUpload,appUpload}.ts. z.compile() produces a flat, loop-free JS fast path for valid inputs and transparently falls back to the standard parser for anything it can't compile (e.g. z.coerce.*, async refinements), so it's safe to apply broadly.
  • Hoisted traccarUpload.ts's getRequestParameters and postPayloadSchema out of the loader/action bodies to module scope — they were being rebuilt (and would have been recompiled) on every request, which defeats the point of compiling once and reusing.

Notes

  • Several schemas (e.g. normalizedMessageSchema, getRequestParameters) rely heavily on z.coerce.*, which compile() intentionally ejects on and falls back to the interpreter for — so those specific schemas won't see a parse-speed win from compile() itself, but they still benefit from the 4.5 memory improvements and from no longer being rebuilt per-request.

Test plan

  • npx react-router typegen && npx tsc -b --noEmit — no new type errors (2 pre-existing, unrelated drizzle-orm errors remain on both base and this branch)
  • Sanity-checked z.compile() at runtime: valid/invalid parses behave identically, and a z.coerce.* schema gracefully falls back instead of erroring

Generated by Claude Code

Bumps zod for the 4.5 memory-footprint improvements (lazy method
memoization) and adopts z.compile() on the validation schemas used for
device upload endpoints and the logbook config, so repeated parses skip
the interpreter for the fast path. Also hoists traccarUpload's schemas
to module scope so they are only constructed (and compiled) once
instead of on every request.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NCUNhjSkdTDxBbdC9FHpi6
@Jbithell
Jbithell marked this pull request as ready for review August 29, 2026 16:04
Copilot AI lite review requested due to automatic review settings August 29, 2026 16:04
@Jbithell
Jbithell merged commit 38fdb46 into main Aug 29, 2026
@Jbithell
Jbithell deleted the claude/zod-upgrade-compile-laqlve branch August 29, 2026 16:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR upgrades zod in the website workspace and applies z.compile() to a set of frequently used schemas so they can be compiled once and reused, reducing per-request/per-parse overhead on hot paths.

Changes:

  • Bump zod from 4.4.3 to 4.5.2 in website/package.json and update website/package-lock.json.
  • Wrap several request/logbook schemas with z.compile() to enable Zod’s compiled fast path where applicable.
  • Hoist traccarUpload request/POST schemas to module scope to avoid re-creating/re-compiling them per request.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
website/package.json Updates zod dependency to ^4.5.2.
website/package-lock.json Lockfile updated for the zod bump (and associated metadata changes).
website/app/routes/api/traccarUpload.ts Hoists and compiles schemas at module scope to avoid per-request rebuild.
website/app/routes/api/flespiUpload.ts Compiles message schemas used in request processing.
website/app/routes/api/appUpload.ts Compiles request validator schema.
website/app/logbook/config.ts Compiles the logbook config schema used during logbook building.
Files not reviewed (1)
  • website/package-lock.json: Generated file

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread website/package-lock.json
Comment on lines 1717 to 1722
"arm"
],
"dev": true,
"libc": [
"glibc"
],
"license": "LGPL-3.0-or-later",
"optional": true,
"os": [
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants