Hi, here is a very short test app:
#include "../JuceLibraryCode/JuceHeader.h"
class App : public JUCEApplication, public AsyncUpdater {
public:
App() {}
const String getApplicationName() { return "test_juce"; }
const String getApplicationVersion() { return "1.0"; }
void initialise(const String &) {
triggerAsyncUpdate();
}
void handleAsyncUpdate() {
int n = 0;
while (!MessageManager::getInstance()->hasStopMessageBeenSent()) {
double t0 = Time::getMillisecondCounterHiRes();
MessageManager::getInstance()->runDispatchLoopUntil(1);
double t1 = Time::getMillisecondCounterHiRes();
if (t1 - t0 > 50) { DBG("WTF, dispatch loop took: " << t1-t0 << " ms"); }
if ((++n)%1000 == 0) { DBG(n/1000); }
}
}
void shutdown() {}
};
START_JUCE_APPLICATION(App)
And here is the output I am getting when I run it on my mac:
JUCE v5.1.1
WTF, dispatch loop took: 6009.07 ms
1
2
3
4
5
6
7
8
WTF, dispatch loop took: 10001.5 ms
WTF, dispatch loop took: 3994.49 ms
WTF, dispatch loop took: 1148.99 ms
WTF, dispatch loop took: 5899.7 ms
WTF, dispatch loop took: 20002.8 ms
So I wonder what is going on with the message loop. It is the call to ‘NSApp nextEventMatchingMask’ which takes all that time. Even if I set the ‘untilDate:’ argument to [NSDate distantPast]’ instead of ‘untilDate: [NSDate dateWithTimeIntervalSinceNow: 0.001]’ , I still end up with calls to nextEventMatchingMask that take 20 seconds to complete. For some reason, clicking on the application icon seems to release whatever is clogging up the event queue.