Skip to main content

Advanced Android Thread Performance

Projects created with the Snapdragon Spaces Unity package can register threads with Snapdragon Spaces Services to improve scheduling priority on Android.

Identifying appropriate priority for threads can help deliver frames quickly and consistently, and improve the XR experience.

By default, the Snapdragon Spaces Unity plugin will identify the Unity main thread and render thread to Snapdragon Spaces Services without any action needed by the developer.

The SpacesThreadUtility class exposes a single method to developers: public static void SetThreadHint(SpacesThreadType threadType). This can be used to identify other developer-created threads.

This method must be called from the thread that should be registered. It should be called as early as possible in the lifetime of that thread for best results.

Four thread types are defined:

  • SPACES_THREAD_TYPE_APPLICATION_MAIN
  • SPACES_THREAD_TYPE_APPLICATION_WORKER
  • SPACES_THREAD_TYPE_RENDERER_MAIN
  • SPACES_THREAD_TYPE_RENDERER_WORKER

Assigning any of the first three thread types SPACES_THREAD_TYPE_APPLICATION_MAIN, SPACES_THREAD_TYPE_APPLICATION_WORKER, SPACES_THREAD_TYPE_RENDERER_MAIN currently has no affect on scheduling priority.

Threads assigned SPACES_THREAD_TYPE_RENDERER_WORKER will be scheduled with a higher priority than other threads.

In practice, these threads will yield less often and spend more time executing code.

Developers should use this sparingly. It is recommended that developers benchmark the performance change of identifying threads in this way themselves.

There is a small overhead to registering a thread with Snapdragon Spaces Services, so this may not be appropriate for extremely short-lived threads.

Identifying non-rendering threads as SPACES_THREAD_TYPE_RENDERER_WORKER could adversely affect the XR experience by taking priority away from rendering threads and can cause decreased FPS, increased latency, reduced stability etc.