-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve NotificationCenter speed and usability #4414
Comments
Is Will a new thread be introduced that performs notification dispatching to registered observers to avoid the "inline" handling function? |
Rather than one class making do too much, I'd prefer a new class that does things differently, but in one specific way only. |
No,
Yes, there should be a "dequeuer", running in a thread, dequeuing notifications and notifying observers. Every observer should have two function pointers: Matching could be done through an The goals are to (1) decouple event posting from handling and (2) avoid notifying non-interested observers (currently, there is no way to indicate interest in just a subset of notifications of certain type - every subscriber to a Notification subtype gets all the notifications of that type, plus there's a |
I made |
* feat(AsyncObserver): Improve NotificationCenter speed and usability #4414 * fix(Notification): add missing header * feat(Any): add checkers for holding nullptr #4447 * feat(NotificationCenter): g++ build and refactoring #4414 * fix(Observer): compile errors on some compilers #4414 * fix(NotificationCenter): compile errors #4414 * chore(ParallelSocketAcceptor): remove unnecessary include and using from header * feat(AsyncNotificationCenter): add #4414 * test(AsyncNotificationCenter): add mixed observer types to the test #4414 * fix(AsyncNotificationCenter): hangs on program exit #4414 * fix(dev): friend not honored, temporarily make private members public * fix(AsyncNotificationCenter); remove default #4414
Is your feature request related to a problem? Please describe.
Currently, the
NotificationCenter
calls(N)Observer
callback in the same thread where the subscribed-to event occurs. This slows down the event collection by executing the handling functionality "inline" in the event collection loop.Additionally, notification dispatch in
(N)Observer
depends ondynamic_cast
to determine whether to actually post theNotification
to theObserver
. The downside of this approach (aside from thedynamic_cast
performance hit) is that it is not possible to distinguish observers by any other criteria except the compile-time notification type.Describe the solution you'd like
Decoupling event detection from handling would allow to collect event-generating data without being slowed down by the processing workload.
Adding an additional (runtime) matching criteria would relax the current constraints and only actually interested observers could be determined prior to dynamic casting and calling the handler.
NotificationCenter
:enqueueNotification()
NObserver
(all optional,*
is only to describe what it conceptually is, could also be aunique_ptr
):dequeueNotification()
NotificationQueue*
Poco::Thread*
Dispatcher*
(Runnable
child)(*match)(const Poco::Any&)
callbackDescribe alternatives you've considered
Alternatively, this could be implemented as a separate pair of classes, inheriting from the existing ones (eg.
ActiveNotificationCenter
andActiveObserver
)Additional context
All this should be added as a default-off option, ie. without affecting the existing functionality.
I'm inclined to deprecate the
Poco::Observer
in the future, eventually renamingNObserver
toObserver
with perhaps notifications beingstd::unique_ptr
which are moved into the handlers.The text was updated successfully, but these errors were encountered: