Performance issue with MLDepthCamera.GetLatestDepthData

I’ve noticed a performance issue with the MLDepthCamera.GetLatestDepthData API which is observable as a regular stutter in the application framerate. I measured the performance of our application with Unity’s Deep Profiling feature, and noticed that this function regularly takes between 10 and 20ms to run. I’ve included a screenshot of the profiler below to help visualize how that delay impacts the performance of our application.

Looking at the ML2DepthCamera file, I noticed that the CreateFromPtr function is copying the frame data on the main thread which is likely the problem. I would like to mitigate the problem by calling that function on a different thread, but the API says the call is not thread safe. Please let me know if there is another workaround that I can use to improve the performance, or if there are plans to optimize this feature.

I believe that comment above the function is incorrect. You should be able to call it from a separate thread.

1 Like