Performance & Development
Understand the performance optimizations and development features built into the documentation system
Caching System
In-Memory Caching
The system uses an intelligent caching layer for expensive file system operations:
- Version list caching: Cached for 5 seconds in dev, 60 seconds in production
- Document list caching: Per-version caching with automatic invalidation
- Individual document caching: Keyed by version and slug
The cache automatically invalidates when MDX or configuration files change in development mode.
Cache Statistics
In development mode, cache operations are logged to the console:
✅ [Cache] hit: getAllDocs:v1.0.0
❌ [Cache] miss: getDocBySlug:v1.0.0:configuration
⏱️ getDocBySlug(configuration): 45.23ms
Hot Reload
Real-Time Updates
The system monitors your docs/ directory for changes and automatically refreshes the page when you save:
- Watches
.mdxfiles for content changes - Watches
_category_.jsonfiles for navigation updates - Uses Server-Sent Events (SSE) for efficient communication
- Only active in development mode
How It Works
- File watcher monitors the
docs/directory recursively - When a file changes, the API sends an event to the browser
- The browser triggers a soft refresh to reload the content
- Cache is invalidated for affected files
Static Generation
Optimized Build Process
The build process uses cached data to speed up generateStaticParams:
1export async function generateStaticParams() {2 const versions = getCachedVersions() // Cached3 const params = []4 5 for (const version of versions) {6 const docs = await getCachedAllDocs(version) // Cached7 for (const doc of docs) {8 params.push({9 version,10 slug: doc.slug.split("/").filter(Boolean),11 })12 }13 }14 15 return params16}Performance Tips
For large documentation sites (1000+ files):
- Use folder organization: Organize docs into logical folders to improve cache locality
- Enable draft mode: Mark work-in-progress docs with
draft: trueto exclude from production builds - Optimize images: Use SvelteKit Image optimization for screenshots and diagrams
- Monitor build times: Watch the performance logs during development
Development Mode Features
Performance Logging
When running npm run dev, you'll see detailed performance metrics:
⏱️ getAllDocs(v1.0.0): 234.56ms
⏱️ getDocBySlug(getting-started): 12.34ms
💾 Memory Usage: { rss: '156MB', heapTotal: '89MB', heapUsed: '67MB' }
Debug Utilities
The system includes helpful debugging tools (dev mode only):
- PerfTimer: Measure operation duration
- logCacheOperation: Track cache hits/misses
- logMemoryUsage: Monitor memory consumption
- debugLog: Pretty-print complex objects
Production Optimizations
Static Site Generation
All documentation pages are pre-rendered at build time:
- Zero server-side rendering overhead
- Instant page loads
- Excellent SEO performance
- CDN-friendly static assets
Bundle Optimization
- Server Components by default (minimal JavaScript)
- Client Components only where needed (tabs, theme switcher)
- Automatic code splitting per route
- Tree-shaking of unused dependencies
Monitoring Performance
Build Analysis
Monitor your build output for performance insights:
1npm run buildLook for:
- Static page generation time
- Number of pages generated
- Bundle size warnings
Development Metrics
During development, watch the console for:
- Cache hit/miss ratios (should improve over time)
- File operation timings (identify slow operations)
- Memory usage patterns (detect memory leaks)
Best Practices
- Keep files organized: Logical folder structure improves caching
- Use frontmatter wisely: Add only necessary metadata
- Optimize content: Large files (>1MB) should be split
- Monitor cache: High miss rates indicate caching issues
- Clean builds: Occasionally clear
.svelte-kit/for fresh builds
Troubleshooting
Slow Build Times
If builds are slow:
- Check for extremely large MDX files (>5MB)
- Reduce the number of concurrent pages being generated
- Clear cache: Delete
.svelte-kit/andnode_modules/.cache/ - Update dependencies to latest versions
Hot Reload Not Working
If changes aren't reflected:
- Check that you're in development mode (
npm run dev) - Look for errors in the browser console
- Verify the
/api/mdx-watchendpoint is responding - Hard refresh the browser (Cmd+Shift+R or Ctrl+Shift+R)
Memory Issues
If experiencing high memory usage:
- Check for circular references in documentation
- Monitor cache size with
getCacheStats() - Reduce
CACHE_TTLinlib/mdx-cache.ts - Clear caches manually with
clearAllCaches()