React Profiler का उपयोग
In this page:
एक Profiling Session Record करना
React DevTools में Profiler tab आपको record click करने, अपने app में कोई interaction perform करने (जैसे एक search box में type करना या एक button click करना), फिर recording stop करके exactly देखने देता है कि कौन से components render हुए, हर एक ने कितना समय लिया, और क्यों।
Flame Graph पढ़ना
Profiler का flame graph हर component को एक colored bar के रूप में दिखाता है — wider/darker bars उन components को represent करते हैं जो render होने में ज़्यादा समय लेते हैं। एक specific render click करना (top पर एक numbered bar) आपको exactly देखने देता है कि उस particular update के दौरान कौन से components render हुए और क्यों।
Production-Like Build के साथ Profiling करना
React का development build extra warnings और checks शामिल करता है जो इसे एक real production build से noticeably slower बनाते हैं। Accurate, real-world performance numbers के लिए, एक production build के against profile करें (या React का profiling build), default development server के against नहीं।
उदाहरण: Building and Previewing Before Profiling
$ npm run build
vite v5.0.0 building for production...
✓ 34 modules transformed.
$ npm run preview
➜ Local: http://localhost:4173/
# open React DevTools Profiler against this URL, not the dev server
⚠️ Run this in your own terminal or Node.js environment.
- कौन से components slow हैं यह guess करना actually एक Profiler session record और पढ़ने के बजाय।
- Development mode में profile करना और मान लेना कि वही exact timings production पर apply होती हैं (development builds में extra checks शामिल हैं जो चीज़ें slow करते हैं)।
- किसी re-render के ACTUAL cause को इसे fix करने की कोशिश से पहले समझने के लिए 'Why did this render?' feature/flame graph उपयोग न करना।
- React DevTools का Profiler tab एक interaction के दौरान हर component के लिए render timings record करता है।
- Flame graph यह visualize करता है कि कौन से components सबसे ज़्यादा समय लिए, और कितनी बार re-render हुए।
- Actual real-world performance numbers check करते समय profiling एक production-like build के साथ होनी चाहिए।
- Specific slow components target करने के लिए Profiler के data का उपयोग करें, guess करने के बजाय।
React DevTools extension React 16.5+ के लिए Profiler support करता है।
Chapter Quiz — Complete all 13 topics to unlock
0/13 topics done
Complete these topics first:
- Why Performance Matters
- Optimizing with React.memo
- Avoiding Unnecessary Re-renders
- Using the React Profiler
- Analyzing Bundle Size
- Image Optimization Techniques
- React as a PWA
- Creating a Production Build
- Environment Variables in React
- Deploying to Netlify
- Deploying to Vercel
- Basic CI/CD for React Apps
- SEO Basics for React SPAs