feat: add React Profiler integration and performance monitoring#520
Merged
RUKAYAT-CODER merged 1 commit intoMay 31, 2026
Merged
Conversation
…fcode#246) - Add `useReactProfiler` hook wrapping React's built-in Profiler API to capture per-component render times and forward them to analytics; slow renders (>16 ms) emit a PERFORMANCE_METRIC event with is_slow: true. - Add `ProfiledScreen` wrapper component composing useReactProfiler with React's Profiler so screens opt in with a single JSX element. - Initialise `webVitalsService` inside AnalyticsProvider so LCP, FID, CLS, FCP and TTFB collection starts automatically on app mount. - Extend PerformanceMetric with RENDER_DURATION and NAVIGATION_LATENCY; extend AnalyticsEvent with REACT_PROFILER_RENDER and REACT_PROFILER_SLOW_RENDER for consistent event naming. - Add unit tests for useReactProfiler and ProfiledScreen. - Add docs/PERFORMANCE_MONITORING.md documenting metric definitions, baselines, usage examples, and regression-alert behaviour. Closes rinafcode#246
|
@Akanimoh12 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements comprehensive performance monitoring for the TeachLink Mobile app, addressing all acceptance criteria in issue #246.
What was added
useReactProfilerhook — wraps React's built-inProfilerAPI to captureactualDurationon every render and forward it tomobileAnalyticsService.trackPerformance. Renders exceedingslowRenderThresholdMs(default 16 ms / 1 frame at 60 fps) additionally emit aPERFORMANCE_METRICanalytics event withis_slow: trueand a Metro console warning for immediate developer visibility.ProfiledScreencomponent — a thin wrapper that composesuseReactProfilerwith<Profiler>so any screen can opt into render-time tracking with a single JSX element:Web Vitals auto-init —
webVitalsService.init()is now called insideAnalyticsProvideron mount, so LCP, FID, CLS, FCP and TTFB collection starts automatically alongside the rest of the analytics stack. Regression detection (>20% worse than the first reading) emits aWEB_VITALS_REGRESSIONevent.Tracking event extensions —
PerformanceMetricgainsRENDER_DURATIONandNAVIGATION_LATENCY;AnalyticsEventgainsREACT_PROFILER_RENDERandREACT_PROFILER_SLOW_RENDERfor consistent naming across the codebase.docs/PERFORMANCE_MONITORING.md— documents all metric definitions, Google's Core Web Vitals thresholds, usage examples, baseline management, and alert behaviour.Tests
tests/hooks/useReactProfiler.test.ts— covers render count accumulation, slow-render detection, custom threshold, high-frequency event-category bypass for analytics sampling.tests/components/ProfiledScreen.test.tsx— covers child rendering, analytics forwarding, screen name propagation, and options prop.Acceptance Criteria Coverage
useReactProfilerhook +ProfiledScreencomponentwebVitalsService.init()wired intoAnalyticsProvidermobileAnalyticsService.trackPerformancecalled on every render; web vitals forwarded viatrackEventPERFORMANCE_METRICevent; 20%-regression gate inwebVitalsServicedocs/PERFORMANCE_MONITORING.mdperformance-baseline.json+ first-reading baseline inwebVitalsServiceAnalyticsProviderinitialises monitoring on every app mount regardless of environmentTest plan
npm test -- tests/hooks/useReactProfiler.test.ts— all assertions passnpm test -- tests/components/ProfiledScreen.test.tsx— all assertions pass<ProfiledScreen name="…">and confirm Metro logs show render timing on each navigationWEB_VITALS_REGRESSIONevent fires when a simulated metric reading exceeds 120% of the baselineCloses #246