Overview
JSFPSMonitor is a low-level utility class that monitors JavaScript thread performance by tracking frames per second (FPS). It provides precise measurements of average, minimum, and maximum FPS over a tracking period.
Import
Usage
Constructor
Methods
startTracking()
Begins tracking JavaScript thread FPS.- Error if tracking is already running
stopAndGetData()
Stops tracking and returns the collected FPS metrics.JSFPSResult object with FPS measurements
Example:
JSFPSResult
averageFPS
Type:number
Mean frames per second across the entire tracking period. Calculated as:
- 55-60: Excellent performance
- 45-55: Good performance
- 35-45: Fair performance
- < 35: Poor performance
minFPS
Type:number
Lowest FPS recorded in any 1-second window during tracking.
Rounded to 1 decimal place.
Use case: Identifies worst-case performance and bottlenecks.
maxFPS
Type:number
Highest FPS recorded in any 1-second window during tracking.
Rounded to 1 decimal place.
Use case: Shows best-case performance when conditions are optimal.
How It Works
Measurement Technique
JSFPSMonitor uses requestAnimationFrame to track frames:
- Frame Counting: Increments a counter on each animation frame
- Time Tracking: Records elapsed time using
Date.now() - Average Calculation: Divides total frames by total elapsed time
- Min/Max Tracking: Calculates FPS in 1-second windows and tracks extremes
Time Windows
The monitor uses sliding 1-second windows:Precision
All FPS values are rounded to 1 decimal place using the internalroundToDecimalPlaces function:
Examples
Basic Measurement
Custom Benchmark Function
Performance Monitoring Hook
Continuous FPS Display
Comparing Operations
Integration with useBenchmark
Best Practices
One Monitor Per Measurement
Meaningful Duration
Always Stop Tracking
Understanding Results
FPS Thresholds
Variance Analysis
Performance Classification
Common Issues
Error: “FPS Monitor already running”
Cause: CalledstartTracking() more than once on the same instance.
Solution: Create a new monitor instance:
Unexpected High/Low Values
Possible causes:- Measurement duration too short
- Other app activity interfering
- Debug mode vs release mode
- Background processes
Min/Max FPS Same as Average
Cause: Measurement period shorter than 1 second. Behavior: When tracking stops before a full second elapses,minFPS and maxFPS default to averageFPS.
Use Cases
Performance Testing
Measure specific operations:A/B Testing
Compare implementation variants:Regression Detection
Monitor performance over time:Custom Benchmarking
Build specialized benchmark tools:Related
- useBenchmark - High-level benchmarking hook
- Benchmarking Overview - Complete benchmarking guide
- AutoScrollHelper - Automated scrolling utility