I work on a macOS app which uses the CoreGraphics APIs to retrieve the whole screen as an image, or the various windows of an application. This is for a screen sharing feature. We occasionally run into an issue where Apple's WindowServer process starts to consume a lot of CPU (close to 100%) and the whole system becomes incredibly sluggish, almost unusable.
If you kill the WindowServer, or kill our app, then things return to normal. The problem persists even when you stop the screen sharing and we aren't calling the APIs anymore, until you terminate our app.
Has anyone worked with the CoreGraphics APIs, or have knowledge of how that connects with the WindowServer process to give some insight into what we might be doing that perturbs the Windows Server in these cases?
A spindump of the system shows that indeed our app and others are waiting on the WindowServer, which is taking up almost all the time of the spindump in its main thread. Seems like some kind of "soft" deadlock, since the WindowServer isn't completely frozen (since the UI is still somewhat accessible). It's an infrequent, but very troublesome occurrence.