djankies/claude-configs/optimizing-performance
Claude Code and agent skill by djankies/claude-configs
- community
Checking that the SKILL.md file is still in the repository.
Optimize Zod validation performance with safeParse, bulk array validation, schema reuse, and passthrough patterns
Install
npx vskill@latest install djankies/claude-configs/optimizing-performanceSKILL.md
The same SKILL.md was published earlier as djankies/claude-configs/optimizing-performance.
Optimizing Zod Performance
Purpose
Guide to performance optimization patterns in Zod v4, leveraging improved parsing speed, reduced bundle size, and efficient validation strategies.
Zod v4 Performance Improvements
Zod v4 introduced major performance gains:
- 100x reduction in TypeScript instantiations (faster compilation)
- 14x faster string parsing (runtime performance)
- 7x faster bulk array validation
- 57% smaller bundle size
- Faster discriminated union parsing
These improvements are automatic when using v4.
Core Optimizations
1. SafeParse vs Parse
SafeParse is 20-30% faster for invalid data:
Why faster:
- No exception throwing overhead
- No stack unwinding
- Predictable control flow
- Better JIT optimization
When to use parse: Internal data that should always be valid (errors are bugs).
2. Schema Reuse
Define schemas at module level, not inside functions:
Performance improvement: 2-5x faster for repeated validations
3. Bulk Array Validation
Use z.array() instead of looping:
7x faster in Zod v4 than item-by-item validation.
4. Discriminated Unions
Use discriminator field for O(1) lookup:
Much faster than regular unions which try each schema sequentially.
5. String Format Functions (v4)
Use top-level functions for 14x faster parsing:
All v4 string formats are optimized: z.email(), z.uuid(), z.url(), z.iso.datetime(), etc.
6. Passthrough Mode
Skip property stripping when not needed:
10-20% faster than strict mode which strips unknown keys.
Use strict for: Security-sensitive data, API responses Use passthrough for: Performance-critical paths, partial validation
Advanced Optimizations
Refinement Order
Place fast refinements first:
Schema Composition
Use extend instead of merge (more performant):
Pick/Omit for Subsets
Faster than redefining the schema.
Bundle Size
Tree Shaking
Zod v4 is fully tree-shakeable. Just import and use:
Zod Mini
For extreme size constraints:
Trade-offs: Smaller bundle (~2KB vs ~14KB), fewer features, same API for basics.
Best Practices Summary
References
- v4 Features: Use the validating-string-formats skill from the zod-4 plugin
- Error handling: Use the customizing-errors skill from the zod-4 plugin
- Testing: Use the testing-zod-schemas skill from the zod-4 plugin
Cross-Plugin References:
- If analyzing schema complexity, use the reviewing-complexity skill for identifying optimization opportunities
Success Criteria
- ✅ Using safeParse instead of parse + try/catch
- ✅ Schemas defined at module level
- ✅ Bulk array validation for collections
- ✅ Discriminated unions where applicable
- ✅ v4 string format functions (14x faster)
- ✅ Passthrough when stripping not needed
- ✅ Refinements ordered by speed
- ✅ Performance monitoring in place
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingzod-4/skills/optimizing-performance/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/djankies/claude-configs/optimizing-performance)