Multithreaded Rendering

caution

It is an experimental feature, which is awesome but not really stable.

Resquare UI supports multithreaded rendering without any extra effort! Once enabled multithreaded rendering, Resquare will allocate a thread for the UI, and the rendering task will run on that thread without blocking the main thread.

caution

You should ensure all functions you called in the component is thread-safe or scheduled to be called in main-thread.

What content will be multithreaded?#

WIP

Enable multithreaded rendering for the UI#

Enable multithreaded rendering is effortless, you just need to set two options as true then Resquare will help you handle it.

createUI(
testComponent, 9, 6, "Test",
multiThreadComponentRender = true,
multiThreadStyleRender = true,
)

Render phases#

When you enable multiThreadComponentRender, your component logic, element, and hooks will run on a new thread, which means you must ensure your component and used components are thread-safe.

When you enable multiThreadStyleRender, the size calculation, position calculation, and item rendering will run on a new thread, it is safe to enable it no matter if your component thread-safe.