sideeffects / HoudiniEngineForUnreal

Houdini Engine Plugin for Unreal Engine.
http://www.sidefx.com/unreal
Other
1.3k stars 368 forks source link

Improve responsiveness of cooking #309

Open KevinCalderone opened 2 weeks ago

KevinCalderone commented 2 weeks ago

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. image

Here is what it looks like after this change, where the HoudiniSchedulerThread handles the task immediately. image