Skip to main content

Runtime kinds

Worklets library differentiate between two types of runtimes - React Native Runtime and Worklet Runtimes. Worklet Runtimes are further divided into UI Runtime and Worker Runtimes.

React Native Runtime - RN Runtime

A runtime spawned by React Native. There's only one React Native in your app. It's the runtime where React lives and the app's JavaScript code is executed. This runtime is executed by the React Native's JS Thread. This is the only runtime that has access to the React Native APIs and the app's state and components.

Worklet Runtime

A runtime spawned by Worklets library. It's pre-configured to be able to execute worklets. It doesn't share any memory with the React Native Runtime or other Worklet Runtimes, but it can communicate with them using specific APIs. It isn't coupled to any thread, but there might be a thread dedicated to its execution.

UI Worklet Runtime - UI Runtime

Special kind of a Worklet Runtime. There's only one UI Runtime in your app. Its primary function is to execute worklets which represent high-priority JavaScript tasks. The UI Runtime is mostly executed by the UI (main) thread. Examples of such tasks are:

  • Synchronous handling of native events.
    Responding to native events like touches on the UI thread allows to react to them on the same frame of the user interaction, without any perceivable delays.

  • Animation calculations.
    Running animations on a main thread, decoupled from heavy business logic on RN Runtime, ensures that they run without interruptions, maintaining stable frame rates.

UI Runtime can be periodically acquired by other threads (other runtimes) to synchronize data.

Worker Worklet Runtime - Worker Runtime

Runtimes spawned by createWorkletRuntime API per user request. Worker Runtimes are designed to execute worklets in a separate thread. They allow for custom parallelization of JavaScript code execution, which can be useful for heavy computations or tasks that don't require immediate interaction with the UI, like data processing or background tasks.