MidiInputs::getDevices() is reaaaally slow


#1

I'm on OSX 10.9.5.   I built a stand-alone version of the demo Midi I/O.   The app takes about 2-3x longer than loading up Finale or Logic 9/X.  When I compile and run my app, it takes it a good 20 seconds to query the system for all midi devices.   Both my app and the Demo's Midi I/O module take this time.   When I boot up finale or logic, they spend about 5 seconds on the "initializing midi" step.   Same for when I open up Audio MIDI Setup and click the refresh button in the MIDI window.   

 

Any ideas why this is so slow?     How about a little tutorial that shows how to implement a wait screen, so it doesn't seem like the app is frozen while the Midi system is queried for devices.   It's annoying to have to wait a good 20+ seconds between when I hit the run button in Xcode and when the application actually opens.  it just sits there in Activity Monitor labeled as "not responding" until this query finishes.

not sure if it helps, but here's the call graph when I sample the process in Activity Monitor:


2558 Thread_2334815   DispatchQueue_1: com.apple.main-thread  (serial)
    + 2558 start  (in libdyld.dylib) + 1  [0x7fff884525fd]
    +   2558 main  (in SimplePiano) + 51  [0x100003e03]  Main.cpp:108
    +     2558 juce::JUCEApplicationBase::main(int, char const**)  (in SimplePiano) + 60  [0x10022043c]  juce_ApplicationBase.cpp:218
    +       2558 juce::JUCEApplicationBase::main()  (in SimplePiano) + 336  [0x1002205f0]  juce_ApplicationBase.cpp:234
    +         2558 juce::JUCEApplication::initialiseApp()  (in SimplePiano) + 21  [0x1003f8a15]  juce_Application.cpp:88
    +           2558 juce::JUCEApplicationBase::initialiseApp()  (in SimplePiano) + 202  [0x10022084a]  juce_ApplicationBase.cpp:261
    +             2558 SimplePianoApplication::initialise(juce::String const&)  (in SimplePiano) + 111  [0x10000404f]  Main.cpp:31
    +               2558 SimplePianoApplication::MainWindow::MainWindow(juce::String)  (in SimplePiano) + 21  [0x100004235]  Main.cpp:79
    +                 2558 SimplePianoApplication::MainWindow::MainWindow(juce::String)  (in SimplePiano) + 184  [0x1000042f8]  Main.cpp:70
    +                   2558 MainContentComponent::MainContentComponent()  (in SimplePiano) + 21  [0x100002a65]  MainComponent.cpp:52
    +                     2558 MainContentComponent::MainContentComponent()  (in SimplePiano) + 996  [0x100002774]  MainComponent.cpp:36
    +                       2558 juce::MidiInput::getDevices()  (in SimplePiano) + 25  [0x100040689]  juce_mac_CoreMidi.cpp:425
    +                         2558 juce::CoreMidiHelpers::findDevices(bool)  (in SimplePiano) + 45  [0x100046bdd]  juce_mac_CoreMidi.cpp:166
    +                           2558 MIDIGetNumberOfSources  (in CoreMIDI) + 178  [0x10113cc8f]
    +                             2558 MIDIProcess::CheckInitialization(int&)  (in CoreMIDI) + 47  [0x101140f3d]
    +                               2558 pthread_once  (in libsystem_pthread.dylib) + 57  [0x7fff84032875]
    +                                 2558 _os_once  (in libsystem_platform.dylib) + 73  [0x7fff8b301156]
    +                                   2558 __pthread_once_handler  (in libsystem_pthread.dylib) + 65  [0x7fff840328d6]
    +                                     2558 MIDIProcess::InitializeOnce()  (in CoreMIDI) + 43  [0x101141f8b]
    +                                       2558 MIDIProcess::Initialize()  (in CoreMIDI) + 221  [0x1011420b5]
    +                                         2558 MIDIClient_RegisterProcess  (in CoreMIDI) + 121  [0x10111445c]
    +                                           2558 mach_msg  (in libsystem_kernel.dylib) + 64  [0x7fff8938ed18]
    +                                             2558 mach_msg_trap  (in libsystem_kernel.dylib) + 10  [0x7fff8938fa1a]


#2

It takes pretty close to 0 seconds on my machine!

The call to MIDIGetNumberOfSources is an OS call, and the juce code only calls it once, so if it goes away for 20 seconds inside there, it must be a particular driver that's struggling for some reason, but I've no idea why or what could be done to change it!