modular-monolith-with-ddd icon indicating copy to clipboard operation
modular-monolith-with-ddd copied to clipboard

InMemoryEventBus Enhancement

Open geekhybrid opened this issue 4 years ago • 2 comments

Hi,

Can we change the data structure which is used to store subscribers (currently a List<HandlerSubscription>) to a more efficient data structure? This will avoid the linear time complexity of getting the right handlers for the published event. A dictionary will be a good choice.

var integrationEventHandlers = _handlers.Where(x => x.EventName == eventType.FullName).ToList();

geekhybrid avatar Dec 13 '20 23:12 geekhybrid

Hi, @geekhybrid. In general you are right that it's more efficient to look up in Dictionary than in List. But:

  1. first of all there may be many handlers for an integration event so we can't use event name as a key in Dictionary
  2. using List in discussing code makes the code natural and easy to read
  3. integration events handlers collection won't have so many items to get perceptible profit in performance with Dictionary

AndreiGanichev avatar Mar 12 '21 14:03 AndreiGanichev

Hi @geekhybrid , @AndreiGanichev

I think it can be a dictionary, I created PR. What do you think?

See https://github.com/kgrzybek/modular-monolith-with-ddd/pull/166

kgrzybek avatar Mar 22 '21 22:03 kgrzybek