I’m doing some low-level optimization in C++ and am running into some large time drifts. For some background:
I have an asynchronous task that’s supposed to perform an operation once per second. Because the operation is just changing the color of a square from black to white to black, I use a photodiode to verify that it indeed happens once per second. However I’m getting a deviation of 10-50ms:
Through testing, I find that the main bottleneck is likely the setVectorParameterValue function, which changes the material of the square from black to white.
Any reason why this might be occurring and how I might be able to further tighten the timing? Or is this just the nature of working with UE? I’m hoping to achieve a deviation of 5ms at most.
Thank you!
-HSM
Just throwing in some ideas:
- have you tried not using setVectorParameterValue and instead swap between two different materials that are constantly black/white to verify your suspicion
- potential inaccuracy of the timer you’re using, have you verified the timer that updates/swaps the material fires reliably once per second? it may help showing what code you have
- latency of the signal to the display, time for the display to update and from the photodiode back to your measuring device
@UnrealEverything Thank you for your response. If you continue have any other ideas please feel free to comment them, it really helps to get another perspective!
Per your points:
-
I actually hadn’t tried that when you suggested it. Ran a quick test to instead change the visibility of the stimulus (to that it’s always drawn on screen, and a 0 is simply changed to a 1). However, because my function is asynchronous, it looks like this can only be done on either the GameThread or SlateLoadingThread. As for your suggestion of swapping between two materials, I believe that would also require a Slate object action.
-
I have verified that the timer performs operations within the desired error bounds. This is done by writing to a CSV file the timestamp at each on-state and off-state of the stimulus. Here are the delays of the CSV file (which are on the order of fractions of milliseconds)
and here is the main loop for my code:
The toSeconds function simply divides the QuadPart by QueryPerformanceFrequency() (Windows API function) to get the time in seconds.
- Our lab runs the same test in MATLAB with the same photodiode, and we find that there is a delay of +/- 3ms. So my guess is that it has to do with Unreal Engine not the photodiode/measuring device. The latency of signal to display can be estimated by comparing the CSV (figure above) and photodiode (figure from initial post) latency results. As for time for display to update, this is a great question that we just got some data for yesterday. According to the test results, the monitor/game FPS does not appear to have an effect on the latency. I plan to do a test on the refresh rate itself by using a different monitor.
I’m also going to try this fix for aync actions with slate on Reddit to implement your suggestion.
Again, please let me know if you have any other ideas!
Thanks again,
-HSM