software-mansion / react-native-reanimated

React Native's Animated library reimplemented
https://docs.swmansion.com/react-native-reanimated/
MIT License
8.61k stars 1.26k forks source link

Fix error persistancy in Performance Monitor #6198

Open latekvo opened 2 days ago

latekvo commented 2 days ago

issue:

Issues which occur on CircularBuffer's total runtime accumulator, persist over the entire runtime these issues are frequent, and occur due to dropped frames, which are almost guaranteed to happen to some degree. After a couple minutes of runtime, effects were noticeable. Previous implementation is also very prone to higher error rates at lower frame-rates.

solution:

Implement Performance Monitor's frame storage in a self-regenerating way. While I still use the circular buffer, the accumulator is saved and reset every revolution, it's state persists for one more revolution, but is completely wiped after that, thus errors don't persist for more than 2 revolutions of the frame buffer (by default: 66ms).


Additionally, I added a dynamic update speed, which normalizes the time to complete the circular buffer revolution. By default, this time is equal to 0.33s, but can be changed by adjusting newly added expectedFps and smoothingCoefficient props.