Comments (9)
I think the main issue comes from the fact that Skia implemented arrays without copying values - in Reanimated arrays are copied when transformed back and forth. The relevant code is found here:
react-native-reanimated/Common/cpp/SharedItems/Shareables.cpp
Lines 171 to 175 in 469d708
from react-native-reanimated.
Hey! π Thanks for the report and the prepared benchmarks! π We will definitely take a look at them and try to make it faster!
from react-native-reanimated.
@marcocaldera I've just noticed that you're using Reanimated 3.6.1 β is this issue reproducible also on the latest version (currently 3.8.1)? I'm asking because in 3.7.0 we've released a huge improvement (#4300) that can positively affect the performance when shared values are updated frequently on the UI thread.
from react-native-reanimated.
@ranaavneet I'm afraid it all depends on the benchmark; as far as I remember in our initial benchmarks held by @piaskowyk we got 20% performance improvement, but obviously we can't predict all usages. Thanks for referencing #5816, we'll keep that in mind.
from react-native-reanimated.
@marcocaldera I've just noticed that you're using Reanimated 3.6.1 β is this issue reproducible also on the latest version (currently 3.8.1)? I'm asking because in 3.7.0 we've released a huge improvement (#4300) that can positively affect the performance when shared values are updated frequently on the UI thread.
Interesting. I run a set of tests based on two new things:
- reanimated 3.8.1
- using an array buffer
UI thread runs now at 60 FPS everywhere. JS thread seems to suffer more on certain occasions.
Flashlight report on Samsung A51:
In the flashlight report maybe it's not super evident but the reanimated performance in terms of FPS is around 55 now (a nice improvement).
As you can see using ArrayBuffer leads to great performance.
from react-native-reanimated.
@marcocaldera That's right, ArrayBuffer
is a powerful data structure. Glad we added support for it in #5223 π
We were also considering adding support for SharedArrayBuffer
so that you can modify it safely from both runtimes (RN and UI), do you think it would be useful?
I suspect that the current approach is to use .modify
but under the hood it calls runOnUI
so the update from RN runtime is asynchronous. Instead, we could update the buffer directly (with proper synchronization).
from react-native-reanimated.
@chrfalch Could you please share more details on that? Assuming that accessing these arrays doesn't require any additional blocking synchronization, how is that possible?
@tomekzaw: So sorry for the delay in getting back on this one. This feature was removed from Skia as previously stated, but the idea is still valid. Here is (from the top of my head what I did).
The array wrapper will be the owner of the array data, so when constructed it converts all JSI values to C++ values to be able to marshall back and forth on different UI runtimes. This gives us the possibility of keeping memory references to the same memory locations (as you also describe) throughout the lifetime of the array wrapper.
In addition we look at reading and writing as two very different operations - where reading is thread safe and available without locking - and writing is protected by a lock in the wrapper.
This way we get the benefit of not copying the data when moving between runtimes, and also the speed of reading without locking - and finally the necessary protection of write operations.
Hope this makes sense :)
from react-native-reanimated.
in Reanimated arrays are copied when transformed back and forth
That's correct, when you copy any value from let's say RN to UI runtime, they are first serialized from JS values in source runtime into runtime-agnostic C++ data structures (so-called "shareables") and re-created on the target runtime as JS values.
Skia implemented arrays without copying values
@chrfalch Could you please share more details on that? Assuming that accessing these arrays doesn't require any additional blocking synchronization, how is that possible?
from react-native-reanimated.
@marcocaldera I've just noticed that you're using Reanimated 3.6.1 β is this issue reproducible also on the latest version (currently 3.8.1)? I'm asking because in 3.7.0 we've released a huge improvement (#4300) that can positively affect the performance when shared values are updated frequently on the UI thread.
Hey @tomekzaw isnt this conflicting the issue reported in #5816. This benchmark in this issue states the opposite of #4300
from react-native-reanimated.
Related Issues (20)
- Animated.createAnimatedComponent() TypeError: Cannot read property 'remove' of undefined HOT 1
- [Android-IOS] [3.11.0] Animation update incorrect when setState after set shared value HOT 5
- NodesManager causing an app crash because of the "Map already consumed" HOT 2
- error: variable length arrays in C++ are a Clang extension [-Werror,-Wvla-cxx-extension] HOT 3
- [Reanimated] Babel plugin exception: TypeError: (0 , types_12.cloneNode) is not a function HOT 1
- Unable to run on Android HOT 3
- ReferenceError: _updateDataSynchronously is not defined HOT 2
- [3.6.0] pod install error after upgrading 3.6.0 HOT 4
- Problems with react-native-reanimated v3.11.0 e react-native v 0.74.1 HOT 5
- Unable to resolve module ./publicGlobals HOT 4
- γBugγModal displays incorrectly if use reanimated HOT 7
- [3.11.0] Plugin does not traverse node_modules, only the root of the project HOT 2
- Flickering in animation after updating react native HOT 11
- 1st item in an inverted list is no longer animated after a while with itemLayoutAnimation HOT 1
- expo 51.0.7 CRASH [TypeError: animatedRef.getTag is not a function (it is undefined)] HOT 3
- useAnimatedKeyboard break navigation color HOT 5
- Found Error TypeScript when run yarn tsc HOT 2
- Task :react-native-reanimated:buildCMakeRelWithDebInfo[armeabi-v7a] FAILED HOT 4
- Entering and/or layout animation flickering when SafeAreaView is a first parent of an animated component HOT 1
- > java.net.SocketException: Connection reset HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-reanimated.