Android
Hoisting the Rive Worker
Considerations when creating workers.
Creating a worker starts a new thread and initializes the graphics pipeline; is not a free operation.
If a worker is serving multiple Rive instances, hoisting the worker higher up in the Compose tree consolidates asset and graphics pipeline initialization costs. Hoisting can also be utilized to preserve the worker between page navigation. Generally, it makes sense to hoist the worker to the level where it makes sense for caching Rive data.
Workers are not Compose-specific; they can be freely created outside of Composable contexts, and then later used within it. It may be desirable to hoist the worker outside of the Composable context entirely in cases where worker initialization should occur before a Composable screen is loaded. With this approach, you will be responsible for managing the lifecycle of the worker.
Was this page helpful?