[WIP] worklet-thread enabled scene graph #2511
Draft
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.
Currently, our C++ scene graph (SkiaDOM) is mutable and thread-safe. Benchmarks show that we pay the locking price twice:
The current C++ SkiaDOM assumes that it will receive many concurrent updates at the same time. However, the number of updates made on the JS thread (often a few times over a component's lifetime) is much lower than updates from the worklet thread (often every single frame). We think it is more sensible to make the scene graph immutable (a JS thread update clones/edits the tree like in Fabric) and have animation values supported on the dedicated thread. Thanks to the persistent mode of the reconciler, this makes handling concurrency much easier.
Additionally, the SkiaDOM is very hard to maintain due to its thread-safety paradigm. The C++ implementation has a few regressions compared to its JS counterpart, which are hard to fix. We also plan to provide extension points for accessibility, gestures, and layouts, which simply cannot be implemented in the current form of the C++ SkiaDOM.
The goal of this PR is to use the persistent mode of the reconciler (used in Fabric) and have the scene graph run on a worklet thread. The scene graph is immutable (via persistent mode) and supports animation values directly.
This will bring performance improvements:
This PR will also fix current SkiaDOM regressions (bugs with displacement maps, shadows).
This will also allow us to build the following features:
fixes #2429