LaKraven / LKSL

LaKraven Studios Standard Library
http://otapi.com
Other
51 stars 15 forks source link

Event Engine - Dispatch to Listener Buckets instead of Event Thread Buckets #125

Closed LaKraven closed 9 years ago

LaKraven commented 9 years ago

The current logic of progression in the Event Engine is analogous to the following:

This approach is somewhat inefficient in that Event References get pushed into the Queues/Stacks of Event Threads not containing a relevant Listener for a majority of Event Types. This means that each Event Thread is iterating through (likely) more (possibly many more) Events than it needs to.

The most efficient approach would be analogous to the following:

Now when the Event Thread comes to process its Queue/Stack of Events, it contains only Events for which it has associated a relevant Listener.

To implement this, TLKEventListener will need to register itself into a List contained within a Dictionary keyed on the TLKEventClass reference dictated by its overriden (implemented) GetEventClass class function. This occurs when the Register procedure is called. Additionally, TLKEventListener will need to unregister itself from the aforementioned List when its Unregister procedure is called.

This should considerably improve overall performance on large-scale systems (such as game engines) by targeting only those Event Threads interested in said Event Type.

LaKraven commented 9 years ago

Actually turns out I'd already implemented a solution for this! While it does iterate all the Event Threads in turn, it offsets the negligible performance overhead onto the Dispatching Thread rather than the Processing Thread(s)