| name | performance-profiling |
| description | Profile and optimize Resource-Adda performance. Use when investigating slow pages, reducing bundle size, optimizing memory usage, or improving Lighthouse scores. |
Performance Profiling
When to Use
- Page loads slowly
- Bundle size exceeds budget
- Memory usage increasing
- Lighthouse score below target
Procedure
1. Bundle Analysis
ANALYZE=true pnpm build
2. Memory Profiling
node --inspect=9229 backend/src/index.js
3. Database Query Profiling
mongoose.set("debug", true);
const vendors = await Vendor.find({ status: "active" }).lean();
vendorSchema.index({ category: 1, status: 1 });
4. Frontend Profiling
npx lighthouse http://localhost:3000 --output=json
Next.js optimizations:
- Use
next/image for automatic image optimization
- Dynamic imports for heavy components
- Server Components by default (no
'use client' unless needed)
- Geist fonts via
next/font/google (no external font loading)
5. Optimization Workflow
pnpm build
pnpm build
Quick Reference
pnpm build
ANALYZE=true pnpm build
npx depcheck
NODE_OPTIONS="--inspect" pnpm dev
Common Issues
| Issue | Solution |
|---|
| Bundle increased | pnpm why <pkg> for dupes; dynamic imports for routes |
| Slow queries | Add indexes; use .lean(); check N+1 queries |
| Memory leak | Close DB connections in tests; check setInterval |
| Build time high | Use Next.js webpack (default); cache aggressively |