Vite Performance Profiling and Optimization Guide
This document outlines how to use the newly added performance profiling scripts and warmup configuration for the Uptime Watcher application.
๐ง New Scripts Availableโ
Debug & Profiling Scriptsโ
npm run debug:transform
- Shows transform times for each file (identifies slow transformations)npm run debug:vite
- General Vite debug outputnpm run profile
- Runs Vite with CPU profiling enablednpm run profile:debug
- Combines profiling with debug outputnpm run profile:transform
- Shows detailed transform timing informationnpm run dev:profile
- Development server with profiling enablednpm run dev:warmup
- Development server with transform debugging to verify warmup
๐ How to Use Profilingโ
1. Transform Performance Analysisโ
npm run debug:transform
Look for files taking >50ms to transform. Example output:
vite:transform 62.95ms /src/components/BigComponent.vue +1ms
vite:transform 102.54ms /src/utils/big-utils.js +1ms
2. CPU Profilingโ
npm run profile
- Visit your site in the browser
- Press
p + enter
in terminal to record profile - A
.cpuprofile
file will be generated - Open with tools like:
- Speedscope (online)
- Chrome DevTools Performance tab
- VS Code flame graph extensions
3. Monitoring Warmup Effectivenessโ
npm run dev:warmup
Check that warmed files show as already cached on first request.
๐ Warmup Configurationโ
The following files are pre-warmed for optimal performance:
Core Applicationโ
./src/App.tsx
- Main app component./src/main.tsx
- Entry point
State Management (Zustand stores)โ
./src/stores/sites/useSitesStore.ts
- Site data management./src/stores/settings/useSettingsStore.ts
- App settings./src/stores/ui/useUiStore.ts
- UI state./src/stores/error/useErrorStore.ts
- Error handling
Theme Systemโ
./src/theme/components/ThemeProvider.tsx
- Theme context./src/theme/components/ThemedBox.tsx
- Common box component./src/theme/components/ThemedButton.tsx
- Common button./src/theme/components/ThemedText.tsx
- Common text./src/theme/useTheme.ts
- Theme hook
Chart Components (Chart.js - Heavy)โ
./src/components/SiteDetails/charts/ResponseTimeChart.tsx
./src/components/SiteDetails/charts/UptimeChart.tsx
./src/components/SiteDetails/charts/StatusChart.tsx
./src/components/common/HistoryChart.tsx
Chart Utilitiesโ
./src/services/chartConfig.ts
- Chart.js configuration./src/utils/chartUtils.ts
- Chart utility functions
Key Componentsโ
./src/components/Dashboard/SiteList/SiteList.tsx
- Main dashboard./src/components/Header/Header.tsx
- App header./src/components/SiteDetails/SiteDetails.tsx
- Site details view
Shared Infrastructureโ
./shared/types/index.ts
- Type definitions./shared/utils/environment.ts
- Environment utilities
๐ฏ Performance Benefitsโ
Expected Improvements:โ
- Faster Initial Load - Pre-warmed files ready immediately
- Reduced Request Waterfalls - Critical imports cached
- Better Chart Performance - Chart.js components pre-loaded
- Smoother Navigation - Core components ready
Monitoring Results:โ
Use npm run dev:warmup
to verify files are being warmed up correctly.
๐ Identifying Additional Warmup Candidatesโ
Finding Slow Files:โ
npm run debug:transform
Look for:
- Files taking >50ms to transform
- Frequently imported utilities
- Large component trees
Finding Import Waterfalls:โ
npm run profile
# Navigate your app, then press p + enter
Look for sequential import chains in the CPU profile.
๐ Notesโ
- Don't over-warmup: Only warm frequently used files to avoid startup overhead
- Monitor bundle size: Warmup doesn't change bundle size, just loading timing
- Profile regularly: Re-profile after major changes to identify new bottlenecks
- Use --open: Consider adding
server.open
for automatic warmup on startup
๐จ Troubleshootingโ
Profile files not generating?โ
- Ensure you press
p + enter
in the terminal running Vite - Check current directory for
.cpuprofile
files
Transform times seem wrong?โ
- Times are estimates due to async operations
- Look for relative patterns, not absolute numbers
- Use multiple runs for consistency
Warmup not working?โ
- Check file paths are correct relative to project root
- Verify files exist and are valid TypeScript/JavaScript
- Monitor console for warmup-related errors