Permalink
Browse files

[WIP] First pass at no-listener optimizations

1) Reduce publish cost, by having more stuff on CE proto.

2) Reduce publish cost, by having _subscribers/_afters arrays be lazy.

3) Reduce new ET cost/new CE cost by mimimizing props to iterate through
   (avoid "undefined" props, masking falsey default values).

4) Reduce new ET cost, by having targets map be lazy.

5) Reduce new ET cost by avoiding stamp() on _yuievt. Didn't seem like id was
   being used.

6) Provide fast track for fires with no potential subscribers, but
   with a defaultFn (needs testing)

All library tests run through `yogi test` pass.

[Total]: Passed: 10726 Failed: 0 Total: 10811 (ignored 85) (8 minutes, 24 seconds)

NOTE: Will check in updated tests, due to removed/modified internal properties and
lazy _subscribers/_afters arrays, in separate commit.

Next up for evaluation
----------------------

A) See if we can have defaults in ET, be inherited (flip Y.CE.prototype if you will),
   instead of mixed in. Tests show that new Y.CE is better than Object.get(), which
   was considered. So staying with FnConstructors for now. http://jsperf.com/create-new

B) The type/Y.cached handling is worth optimizing, as mentioned before, by passing
   through the calculated type.

C) See if we can have a private getSubs(), hasSubs() which can return faster, and avoid
   creating arrays, unless there are subscribers. The above 2 methods are public, so
   can't mess with those.

D) See if we can get by with holding onto the opts for publish, without creating a new
   Y.CustomEvent, on publish (maybe optionally, based on lazyPublish config?).

Numbers
-------

This commit (ops/sec):

new Base() x 18,894
Publish x 1,714,575
Publish - 10 different events x 152,180
Fire - 10 different events, no listeners x 36,957
EventTarget Construction + Publish(foo) + Fire(foo) - no listeners x 158,325
Subscribe + Fire - 10 different events x 381
EventTarget Construction + Publish(foo) + Subscribe(foo) + Fire(foo) - 10 listeners x 23,252
EventTarget Construction + Publish(foo) + Subscribe(foo) + Fire(foo) - 2 listeners x 58,334
Fire With Payload - 10 listeners x 130,708
Fire - 10 listeners x 163,150
Fire With Payload - 2 listeners x 181,028
Fire - 2 listeners x 195,069

3.8.1 (ops/sec):

new Base() x 15,606
Publish x 1,662,980
Publish - 10 different events x 124,112
Fire - 10 different events, no listeners x 20,458
EventTarget Construction + Publish(foo) + Fire(foo) - no listeners x 97,666
Subscribe + Fire - 10 different events x 365
EventTarget Construction + Publish(foo) + Subscribe(foo) + Fire(foo) - 10 listeners x 22,867
EventTarget Construction + Publish(foo) + Subscribe(foo) + Fire(foo) - 2 listeners x 51,528
Fire With Payload - 10 listeners x 135,688
Fire - 10 listeners x 167,362
Fire With Payload - 2 listeners x 151,447
Fire - 2 listeners x 206,144
  • Loading branch information...
1 parent 6f1f470 commit 8a46d6999042c2c4b96b13d02b1000e888ebba36 @sdesai sdesai committed Mar 11, 2013
Oops, something went wrong.

0 comments on commit 8a46d69

Please sign in to comment.