Performance Optimization Guide
Overview
This document outlines the performance optimizations implemented in Dashtray to ensure fast load times, smooth interactions, and efficient resource usage.Bundle Optimization
Code Splitting
The application uses manual chunk splitting to optimize caching:- vendor-svelte: Core Svelte runtime
- vendor-convex: Convex client and bindings
- vendor-ui: UI component libraries (bits-ui, vaul-svelte, svelte-sonner)
- vendor-charts: Chart libraries (layerchart, d3-scale, d3-shape)
- vendor-dnd: Drag-and-drop libraries
Build Configuration
Lazy Loading
Components and routes are lazy-loaded using dynamic imports:Database Query Optimization
Indexes
All frequently queried fields have indexes:- projects:
by_slug,by_owner,by_subscription_tier,by_subscription_status - metrics:
by_project,by_connection,by_timestamp,by_project_and_metric,by_project_and_timestamp - dashboards:
by_project,by_slug,by_type,by_project_and_type - connections:
by_project,by_service,by_status,by_project_and_service
Query Patterns
- Use compound indexes for multi-field queries
- Paginate large result sets (limit + cursor)
- Aggregate at query time instead of fetching all data
- Cache frequently accessed data (5-minute TTL)
Example Optimized Query
Caching Strategy
Client-Side Caching
ThequeryCache utility provides in-memory caching:
Cache Invalidation
Invalidate cache when data changes:Cache TTLs
- Metrics: 5 minutes
- Dashboards: 10 minutes
- Projects: 15 minutes
- Connections: 5 minutes
Image Optimization
OptimizedImage Component
Use theOptimizedImage component for automatic lazy loading:
Features
- Lazy loading with Intersection Observer
- Loading skeleton
- Error handling
- Priority loading for above-the-fold images
Best Practices
- Always specify
widthandheightto prevent layout shift - Use
priority={true}for above-the-fold images - Use WebP/AVIF formats when possible
- Compress images before upload (max 2MB)
Performance Utilities
Debounce and Throttle
Performance Measurement
Adaptive Loading
Network Optimization
Request Batching
Batch multiple requests into a single query:Prefetching
Prefetch routes and data on hover:Rendering Optimization
Virtual Scrolling
For large lists (>100 items), use virtual scrolling:Reduced Motion
Respect user preferences:Monitoring
Core Web Vitals
Monitor these metrics:- LCP (Largest Contentful Paint): < 2.5s
- FID (First Input Delay): < 100ms
- CLS (Cumulative Layout Shift): < 0.1
Performance Budget
- Initial bundle: < 200KB (gzipped)
- Total page weight: < 1MB
- Time to Interactive: < 3s
- API response time: < 200ms
Monitoring Tools
- Sentry for error tracking and performance monitoring
- Mixpanel for usage analytics
- Cloudflare Analytics for CDN performance
Testing Performance
Lighthouse
Run Lighthouse audits regularly:Slow Connection Testing
Test on slow connections:Bundle Analysis
Analyze bundle size:Checklist
- Bundle size < 200KB (gzipped)
- All images lazy-loaded
- Database queries use indexes
- Caching implemented for frequently accessed data
- Virtual scrolling for large lists
- Debounce/throttle expensive operations
- Prefetch critical routes
- Code splitting for large dependencies
- Lighthouse score > 90
- Core Web Vitals in green