I have a real time 3d program using OpenFrameworks that runs easily at 60 fps under normal conditions on a single thread. I have a 2nd auxiliary thread that while working causes my main thread update rate to drop and stall intermittently.
In order to debug the situation I have tried to isolate the issue by the following:
- The main thread does relatively little work in my test conditions, and achieves 2000fps when the auxiliary thread is running.
The second thread runs in a continuous loop and tries to load a large (20Meg) xml file via the following
while (true) { ofXml test; test.load("bigfile.xml"); }
There are no programmatically shared resources between the main thread and auxiliary thread and there are no locks/mutexes in either thread.
Profiling seems to give me one possible answer, it looks like heap allocations and deallocations on the auxiliary thread are possibly swamping the heap allocator and therefore the main threads allocations/deallocations are being slowed down.
I used a sampling profiler ",very sleepy", to profile my main thread for 30 seconds first while the auxiliary thread is suspended, and then resumed.
When running with the auxiliary thread suspended , top exclusive% functions are as follows, and a look at stack of the the time taken for new:
And now the same running with the auxiliary thread active:
This seems to suggest that std::string
allocations are being slowed by heap allocations in the auxiliary thread and may be what is causing the slowdown and stalls. Does that sound correct? , or could i be missing something. I want to make sure my analysis is correct before I try to rewrite my code without std::string
.