Upgrade zod to 4.5.2 and use compile() on hot-path schemas - #13
Merged
Conversation
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
There was a problem hiding this comment.
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
zodfrom4.4.3to4.5.2inwebsite/package.jsonand updatewebsite/package-lock.json. - Wrap several request/logbook schemas with
z.compile()to enable Zod’s compiled fast path where applicable. - Hoist
traccarUploadrequest/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 on lines
1717
to
1722
| "arm" | ||
| ], | ||
| "dev": true, | ||
| "libc": [ | ||
| "glibc" | ||
| ], | ||
| "license": "LGPL-3.0-or-later", | ||
| "optional": true, | ||
| "os": [ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
zodfrom4.4.3to4.5.2inwebsite/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).z.compile()where it can actually take effect:website/app/logbook/config.ts(logbookConfigSchema, which is parsed per device/day when building logbooks) andwebsite/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.traccarUpload.ts'sgetRequestParametersandpostPayloadSchemaout of theloader/actionbodies 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
normalizedMessageSchema,getRequestParameters) rely heavily onz.coerce.*, whichcompile()intentionally ejects on and falls back to the interpreter for — so those specific schemas won't see a parse-speed win fromcompile()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, unrelateddrizzle-ormerrors remain on both base and this branch)z.compile()at runtime: valid/invalid parses behave identically, and az.coerce.*schema gracefully falls back instead of erroringGenerated by Claude Code