AppKit always stalls on first Keyboard event?

I have a custom view setup to receive keyDown, keyUp, and flagsChanged events. When I first launch my app and press a key on the keyboard, I consistently see a half-second stall/hiccup before my keyDown handler is invoked. Subsequent key presses trigger the handler instantly.

This is a barebones app with no other logic running, so there shouldn't be any performance bottlenecks.

I see the same hiccup (though less consistently) when my app regains focus--it can take over a second before AppKit starts pumping my keyboard events again.

I checked the backtrace when my keyDown handler is called, and I don't see anything weird:

* frame #0: 0x0000000100008ea4 Sim`-[SimMetalView keyDown:](self=0x000000010022e880, _cmd="keyDown:", event=0x000000010034e6d0) at macos_sim.m:1795:2
* frame #1: 0x00007fff2b9942ad AppKit`-[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 6512
* frame #2: 0x00007fff2b992719 AppKit`-[NSWindow(NSEventRouting) sendEvent:] + 349
* frame #3: 0x00007fff2b99144e AppKit`-[NSApplication(NSEvent) sendEvent:] + 2826
* frame #4: 0x00007fff2b7ddbdf AppKit`-[NSApplication run] + 707
* frame #5: 0x000000010000bfc5 Sim`main(argument_count=1, argument_input=0x00007ffeefbff888) at macos_sim.m:1974:2
* frame #6: 0x00007fff682a7cc9 libdyld.dylib`start + 1
* frame #7: 0x00007fff682a7cc9 libdyld.dylib`start + 1

I tried posting an empty event in applicationDidFinishLaunching to see if that would jumpstart the event loop, but that didn't help. I also tried setting the event supression interval to 0, which also did nothing:

CGEventSourceRef input_event_source = CGEventSourceCreate( kCGEventSourceStateHIDSystemState );
CGEventSourceSetLocalEventsSuppressionInterval( input_event_source, 0 );

What could be causing this delay in receiving keyboard events? What are my options for getting instant access to keyboard events?

Thank you!

I've been playing around with this more and noticed that I only see the hitch when I'm running my application with the LLDB debugger connected. If I run my app standalone, it seems to work without a hitch.

Could LLDB be interfering with NSEvent dispatch somehow? Is LLDB doing its own processing on my key events before it reaches my app?

AppKit always stalls on first Keyboard event?
 
 
Q