sideeffects / HoudiniEngineForUnreal

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

Latency synchronizing cook completed state #310

Open KevinCalderone opened 2 weeks ago

KevinCalderone commented 2 weeks ago

Problem

There is a large latency in how the cook completed state is synchronized between the Houdini application and the HoudiniSchedulerThread. This is causing an unnecessary random 0ms-100ms latency to get added to all cook operations.

This issue is similar to what I described in this PR: https://github.com/sideeffects/HoudiniEngineForUnreal/pull/309

A cook is performed on the HoudiniSchedulerThread by calling FHoudiniApi::CookNode. (See: FHoudiniEngineScheduler::TaskCookAsset)

The HoudiniSchedulerThread then spins in a wait loop calling FHoudiniApi::GetStatus periodically to check when the cook is completed. (See: Bottom of FHoudiniEngineScheduler::TaskCookAsset).

The frequency of this polling is controlled by FHoudiniEngineScheduler::UpdateFrequency which is currently set to 100ms. This is causing there to be a random 0ms-100ms of unnecessary latency in the cook operation completing.

Possible Solutions

I am not sure what the best solution to this problem is.

The HAPI does allow you to stall the thread until the cook operation is complete. However this would break the other functionality in this function of periodically sending cook state notifications while in the wait loop.

Here are some possible solutions:

1. Increase the polling frequency

2. Stall the HoudiniSchedulerThread and move the cook state update loop to a different thread.

3. Use a second worker thread that stalls and signals the cook complete signal back to HoudiniSchedulerThread using an FEventRef.

4. Stall the HoudiniSchedulerThread only if the "Display Slate Cooking Notifications" option is turned off.

4. Expose a wait with timeout primitive in the HAPI.