On Mar 22, 2014, at 2:56 PM, David Blevins <david.blev...@gmail.com> wrote:

> 
> On Mar 22, 2014, at 4:15 AM, Romain Manni-Bucau <rmannibu...@gmail.com> wrote:
> 
>> removed after and replaced all the boilerplate we added with 
>> AfterEvent<Event>.
> 
> Love it.  Looks very elegant.  Added a BeforeEvent to round it out.
> 
> Have some ideas to optimize.  Ideally before/after could be zero cost unless 
> there are actually observers for them
> 
> Off to the airport, hacking on the plane.

Plane hacking was fruitful.  Basically rewrote all the code.  Did very heavy 
testing on performance with an increasing number of Observers.

High level, things got very slow the more observers we added (even if those 
observers did not observe the event being fired).

It's all been redesigned to achieve 2 goals:

Design notes:

 - Events are zero cost unless observed
 - Before/After are zero cost now unless used
 - Negative hits are zero cost

On my laptop we can push 50 million messages in about 15 or 12 seconds.  About 
18x faster.

At a high level, we now completely calculate all methods that should be invoked 
per event and cache it -- even if the answer is zero.

So basically firing tons of events is "free" and having a ton of observers is 
also "free".

  - you only pay for the events that are actually being listened for and...
  - only in proportion to the number of listeners actually observing that event

Fun side note.  The code is so optimized that if say there is exactly one 
observer method for an event, the cached Invocation object is that exact method 
-- no lists or loops.



-David

Reply via email to