You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add dynamic sampling to frame screenshots (facebook#56048)
Summary:
Update Android frame screenshot processing to skip screenshot capture when encoding is already in progress — now limited to a single background thread — while always emitting frame timing events.
**Motivation**
1. Prevents truncated trace data on slower devices (e.g. missing screenshots for the last 1/3 of the trace), with the tradeoff of some intermediate frame visual snapshot loss.
2. Reduces total recording overhead by freeing up device threads - prevents excessive encoding work from blocking or slowing down the UI and other app threads.
NOTE: ⚠️ This still does not yet solve crashes (OkHttp network chunk size overflow) for heavy frame data at a high FPS on fast devices (coming next).
**Dynamic throttling algorithm**
- Use a single `lastFrameBuffer` to store the most recently captured frame (bitmap + metadata)
- Use a serial background thread (single-thread executor) for all encoding work
- Use an atomic `encodingInProgress` flag to track encoding state
- Always capture screenshots to `lastFrameBuffer` on every frame (even during encoding), replacing any previous waiting frame
- When not encoding: start encoding the captured frame
- When encoding finishes: loop back and check if buffer was refilled, encode that frame if present
- Always emit frame timing events immediately (without screenshot)
This ensures we don't queue up excessive encoding work while maintaining continuous frame timing data and guaranteeing the final settled state of animations is captured (tail-capture), minimizing the performance impact of recording on the device.
NOTE: ⚠️ We do still typically lose a small region of pending frames at the end of a trace, but this is now more reasonable. A further fix (likely unnecessary) is to add lifecycle methods to await frame processing before responding to `Tracing.stop`.
Changelog: [Internal]
Differential Revision: D95987488
Copy file name to clipboardExpand all lines: packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/inspector/FrameTimingsObserver.kt
0 commit comments