Is Darwin Notification Fast Enough for Real-Time Communication Between XPC Clients and Browser Extension?

I have 2 XPC clients and an XPC server. One of the XPC clients is a binary-helper that serves as a native messaging host for the browserExtension. The other XPC client sends a specific event to the XPC server, which then triggers a Darwin notification. The binary-helper observes this Darwin notification and sends a response to the browserExtension.

Currently, we're considering two options to communicate the response from binary-helper to browserExtension:

  1. Polling: Every 5 seconds, the browserExtension checks for a response.
  2. Darwin Notifications: The binary-helper sends a message to the browserExtension as soon as it observes the Darwin notification.

I'm wondering if Darwin notifications are fast enough to reliably deliver this response to the browserExtension in real time, or if polling would be a more reliable approach. Any insights or experiences with using Darwin notifications in a similar scenario would be greatly appreciated.

Answered by DTS Engineer in 824796022
Written by mmaram in 774233021
I'm wondering if Darwin notifications are fast enough to reliably deliver this response to the browserExtension in real time

To have meaningful conversations about real-time computing, you have to specify a time constraint. Without that, we’re just talking about “fast enough, most of the time” (-:

macOS can hit some tight real-time goals pretty consistently, but only in very limited situations. The canonical example of this is audio rendering. The techniques used for that are unlikely to be helpful here. For audio the time constraint is in the tens of microsecond range, whereas I suspect that your time constraint is more like in the tenth of a second range, that is, fast enough so that the user doesn’t notice.

Written by mmaram in 774233021
I have 2 XPC clients and an XPC server.

Are those the only processes involved? If so, you shouldn’t need to mess around with Darwin notifications. Rather, do all your IPC using XPC:

  • If you need the two clients to communicate directly, use the server to pass an endpoint between the two.

  • If you need bidirectional communication, there are various techniques you can use. See the summary in this DevForums post.

Finally, I encourage you to have a look at the links in XPC Resources. There’s a lot of important background there.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Don't forget about long-polling. You poll ever 5 seconds or so, but delay the response for up to 5 seconds. If an event occurs, send a response immediately. If no event occurs, reply with a no-result value after 5 seconds. Worse case condition is an event occurring right at the timeout/reconnect point. The very next long poll will return immediately, but there will be a slight delay.

Apple doesn't make real-time platforms. It's better to think in terms of how fast is fast enough and how much effort you are expending to get there.

Written by mmaram in 774233021
I'm wondering if Darwin notifications are fast enough to reliably deliver this response to the browserExtension in real time

To have meaningful conversations about real-time computing, you have to specify a time constraint. Without that, we’re just talking about “fast enough, most of the time” (-:

macOS can hit some tight real-time goals pretty consistently, but only in very limited situations. The canonical example of this is audio rendering. The techniques used for that are unlikely to be helpful here. For audio the time constraint is in the tens of microsecond range, whereas I suspect that your time constraint is more like in the tenth of a second range, that is, fast enough so that the user doesn’t notice.

Written by mmaram in 774233021
I have 2 XPC clients and an XPC server.

Are those the only processes involved? If so, you shouldn’t need to mess around with Darwin notifications. Rather, do all your IPC using XPC:

  • If you need the two clients to communicate directly, use the server to pass an endpoint between the two.

  • If you need bidirectional communication, there are various techniques you can use. See the summary in this DevForums post.

Finally, I encourage you to have a look at the links in XPC Resources. There’s a lot of important background there.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Is Darwin Notification Fast Enough for Real-Time Communication Between XPC Clients and Browser Extension?
 
 
Q