> Am 30.08.2016 um 06:38 schrieb Stephan Eggermont <[email protected]>:
>
> On 29/08/16 22:37, Denis Kudriashov wrote:
>> It looks quite safe to not check anything because subscription items are
>> instances of AnnouncementSubscription which are created internally
>> inside Announcer during subscription
>
> We should probably do something special for 0 and 1 subscriptions.
>
I think for the 0 case we should think about instantiating the
SubscriptionRegistry lazily. This would also mitigate the effect that if a lot
of announcers are created they create only a single object instead of two until
used. Of course this depends on the probability of having a lot of announcers
where only a few are used.
The #announce: method looks like it has been lazy before.
Announcer>>#announce: anAnnouncement
| announcement |
announcement := anAnnouncement asAnnouncement.
registry ifNotNil: [
registry deliver: announcement
].
^ announcement
checks for #ifNotNil: but registry is created in #initialize. So #ifNotEmpty:
would be right here but #deliver: checks that, too.
For the 1 case we could store a single subscription in the registry field. Both
subscription and registry have the #deliver: method so this would work out of
the box. We could just dispatch the method.
So without having measured it myself it could be good if
- registry is nil if no subscribers are present. With nil checks the Announcer
code could go fast
- registry is a subscription in case of 1 subscriber. No need for
#subscriptionsHandling: because check is directly on the subscription for
#handlesAnnouncement: This should save some cycles and the creation of
intermediate collections. With not using the SubscriptionRegistry there is also
no #critical: section saving the creation of one.
- registry is SubscriptionRegistry in case of >1 subscribers
my two cents,
Norbert