React Native Skia 3.0 moves to Graphite with threaded rendering
React Native Skia 3.0 has been released. A post on its performance, the first part of a series, explains the move from Ganesh to Graphite; part 2, Hello, Graphite: WebGPU, covers the WebGPU integration.
Starting with version 3, the library is published as react-native-skia. Version 2 is still maintained and is also published under the new package name.
From Ganesh to Graphite
Version 2 used a rasterization backend named Ganesh, which binds its GPU context to a single thread, in this case the UI thread. The post says this caused stability issues, since resources created on the JS thread had to be handed over to the UI thread. It also caused performance issues, because every on-screen canvas consumed UI thread frame budget. Ganesh pipelines were also highly specialized per draw, so they could not be compiled ahead of time, and compiled shaders could not be persisted.
Version 3 uses Skia Graphite with a thread pool. Recordings of drawing commands are created on dedicated threads and then submitted, which React Native Skia handles automatically. Images can be drawn without copying by any canvas from any thread, including textures created on the JS thread, camera frames from a frame processor, or images shared with WebGPU. Commands are validated, a lost GPU device is reported and recovered from, and rejected recordings are logged.
Benchmarks
- UI thread: with a Reanimated animation next to the canvas, v3 kept the UI thread at about 120 fps up to 24K rectangles on a Pixel 8 (96.3 fps at 48K), and at 119.8 fps up to 48K on an iPhone 14 Pro. In v2, the Pixel 8 dropped to 1.0 fps at 48K and the iPhone 14 Pro to 4.3 fps.
- Multiple canvases: in v3, splitting 24K rectangles across two canvases drew 1.25 times as many rectangles per second as one canvas on the Pixel 8, and 1.7 times as many on the iPhone 14 Pro. With four canvases, the Pixel 8 runs out of fast cores.
- Android frame pacing: presentation timing no longer depends on draw time. A TextureView canvas, the default for non-opaque canvases on Android, went from 58.7 fps in v2 to 115.9 fps in v3 on a Pixel 8 pinned to 120 Hz.
Pipeline compilation
Graphite uses fewer, more general pipelines, which can be compiled ahead of time on a background thread. Because it runs on Dawn, Google's WebGPU implementation, compiled shaders and pipelines can be persisted to disk. Early experiments show roughly double the frame rate when a Skia drawing loads during a navigation transition; the work to use persisted shaders and pipelines to shorten time to first frame is still in progress.
WebGPU
The post states that the WebGPU integration lets libraries such as Three.js and TensorFlow.js share the same GPU device and resources with React Native Skia, and that Dawn provides YUV texture support and GPU fences for video and camera decoding and encoding. These topics are covered in part 2.
Video
The React Native Skia 3.0 release announcement YouTube
Links
Source: wcandillon.dev