Reduce Reanimated serialization traffic #6219
Merged
+14
−3
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.
This was a major WTF moment for me and I'm still not sure to what extent this is actually useful. However, the Android GPU profiler seems to be happy about this change.
There is some information about how Reanimated closures work here: software-mansion/react-native-reanimated#3670 (comment)
We're closing over
withSpring
which I assume means that this clone function will have to go intowithSpring
itself, deal with its closures over top scope, and so on. I haven't tried logging what's going on there but I suspect there may be some serialization overhead.However, we can just create initial and final values of the animation and expose those to the worklet. I didn't expect this to be faster but it does seem to be. Or maybe the GPU debugger is being misleading.
Test Plan
Enable GPU profiler, build for release on device, remove all embeds (they add too much other unpredictability), continuously scroll a little bit up and down with your finger without releasing on Home.
Before
Overall we're way above the red line.
The green+blue stuff reaches the green line.
After
Overall we're a bit below the red line.
The green+blue stuff is halfway within the green line.