HoudiniEngineForUnreal
HoudiniEngineForUnreal copied to clipboard
Improve responsiveness of cooking
Problem
There is a large latency added to cooking due to how tasks are handed off between threads.
When a cook needs to occur, the main thread enqueues a task for the HoudiniSchedulerThread to execute the cook. (See: FHoudiniEngineManager::StartTaskAssetCooking)
The HoudiniSchedulerThread discovers a new task is available by polling the task queue. (See: FHoudiniEngineScheduler::ProcessQueuedTasks)
The thread only polls the task queue every 100ms. This incurs a random 0ms to 100ms to latency in processing the request. (See: FHoudiniEngineScheduler::UpdateFrequency)
Solution
This PR introduces an FEventRef into the FHoudiniEngineScheduler. The FEventRef is used to wake up the HoudiniSchedulerThread immediately when work becomes available.
This change eliminates any latency caused by the polling. This improves the responsiveness of cooks by on average 50ms.
Unreal Insights Example
Here is a illustration of the problem using Unreal Insights. (My images may look different than yours as I have a number of additional profiling scopes added.)
You can see there is a large delay between FHoudiniEngineManager::ProcessComponents adding the task and the HoudiniSchedulerThread handling the task.
Here is what it looks like after this change, where the HoudiniSchedulerThread handles the task immediately.