macoscocoawebviewipcnsxpcconnection

Using XPC to parallelize Cocoa WebView rendering


My Cocoa app needs to simultaneously render many batches of generated web pages. Since WebKit WebView rendering is restricted to the main thread, I can't use GCD to do this within the application's process, so I'm looking at using some sort of inter-process solution.

NSXPCConnection is the obvious choice, since it plays nice with the sandbox and transparently proxies all the Core Foundation types I'll need to work with. However, it appears to only ever create a single process per service, which just moves my main-thread-restriction into a different process and doesn't let me parallelize multiple rendering requests. Is there any way to convince the XPC system to fork multiple processes for the same service, possibly using the C API (xpc_connection_create, etc.)?

At this point I'm considering make a dozen identical XPCServices bundles with different names and connecting to whichever ones are idle for a particular batch of parallel render requests, but that just seems silly.


Solution

  • FWIW, I opened a technical support issue with Apple, and they responded that "there is no supported way to achieve the desired functionality given the currently shipping system configurations", so I guess it can't be done.

    I wound up creating 20 identical XPC services and launching [[NSProcessInfo processInfo] processorCount] instances and I manually manage communicating with them. It actually works pretty well, and I'm able to max out all the processors with rendering tasks.