Overview
useBenchmark is a React hook that measures FlashList performance by automatically scrolling through your list and tracking JavaScript thread FPS. It provides detailed metrics and actionable suggestions for optimization.
Import
Signature
Parameters
flashListRef
Type:React.RefObject<FlashListRef<any>>
A ref object pointing to the FlashList instance to benchmark.
callback
Type:(benchmarkResult: BenchmarkResult) => void
Callback function invoked when the benchmark completes. Receives a BenchmarkResult object containing metrics and suggestions.
params
Type:BenchmarkParams (optional)
Configuration options for the benchmark.
BenchmarkParams
startDelayInMs
Type:number
Default: 3000
Delay in milliseconds before the benchmark starts automatically. Gives time for the list to initialize and render.
speedMultiplier
Type:number
Default: 1
Multiplier for scroll speed. Higher values scroll faster, lower values scroll slower.
0.5: Slower scroll, tests gentle scrolling performance1: Normal speed, simulates typical user behavior2-3: Fast scroll, stress tests list rendering
repeatCount
Type:number
Default: 1
Number of times to repeat the benchmark cycle (scroll to bottom and back to top).
- Performance degradation over time
- Memory leaks
- Caching effectiveness
- Average performance across runs
sumNegativeBlankAreaValues
Type:boolean
Default: false
When true, cumulative blank area includes negative values (when the list renders faster than scroll speed).
startManually
Type:boolean
Default: false
When true, prevents automatic benchmark start. Use the returned startBenchmark function to trigger manually.
Return Value
startBenchmark
Type:() => void
Function to manually start the benchmark. Only needed when startManually: true.
isBenchmarkRunning
Type:boolean
Indicates whether a benchmark is currently in progress.
BenchmarkResult
js
Type:JSFPSResult | undefined
JavaScript thread FPS metrics:
- averageFPS: Mean FPS across the entire benchmark
- minFPS: Lowest FPS recorded (indicates worst-case performance)
- maxFPS: Highest FPS recorded (indicates best-case performance)
interrupted
Type:boolean
Indicates whether the benchmark was cancelled before completion.
suggestions
Type:string[]
Array of actionable suggestions based on benchmark results.
Common suggestions:
- Low JS FPS: “Your average JS FPS is low. This can indicate that your components are doing too much work. Try to optimize your components and reduce re-renders if any”
- Small data set: “Data count is low. Try to increase it to a large number (e.g 200) using the ‘useDataMultiplier’ hook.”
formattedString
Type:string | undefined
Pre-formatted string containing all results and suggestions, ready to display or log.
Examples
Basic Benchmark
Manual Benchmark with UI
Advanced Benchmark with Analytics
Benchmark with Large Dataset
How It Works
- Initialization: Hook waits for
startDelayInMs(or manual trigger) - FPS Tracking: Starts monitoring JavaScript thread performance using
requestAnimationFrame - Scrolling: Automatically scrolls from top to bottom, then bottom to top
- Repetition: Repeats the scroll cycle
repeatCounttimes - Analysis: Calculates FPS metrics and generates suggestions
- Callback: Invokes callback with complete results
Scroll Behavior
- Scrolls at approximately 7 pixels per millisecond (multiplied by
speedMultiplier) - Uses non-animated scrolling for consistent measurements
- Scrolls to the very bottom and top of the list
- Respects horizontal/vertical list orientation
Best Practices
Testing Environment
Result Handling
Manual Control
Common Issues
Error: “Data is empty, cannot run benchmark”
Cause: FlashList has no data when benchmark starts. Solution: IncreasestartDelayInMs or ensure data loads before benchmark:
Low FPS Results
Possible causes:- Running in debug mode (use release builds)
- Complex renderItem components
- Unnecessary re-renders
- Heavy computations in render
- Missing React.memo optimizations
Benchmark Doesn’t Start
Check:- Ref is properly attached to FlashList
- Component hasn’t unmounted before
startDelayInMs - Data is loaded
- No errors in console
Related
- JSFPSMonitor - Low-level FPS monitoring
- useFlatListBenchmark - FlatList benchmarking
- useDataMultiplier - Data multiplication utility
- Benchmarking Overview - Complete benchmarking guide