yui/yui3 — pull request #572 by sdesai (2013-04-01 18:59:22+00:00)
Title: CustomEvent and EventTarget performance optimizations

# Description

This is a set of 10 commits, aimed at optimizing `CustomEvent` and `EventTarget`, primarily for the "no listeners" code path, however it also helps with custom event in general.

The goal was to improve `new Base()` times. `Base` publishes and fires 2 events (`init` and `initializedChange`) during construction, which for the 80% case, don't have listeners.

In general, the gist for the whole set of changes is:

* Try to fast-path common usage.
* Try and avoid the cost of the 20% features on the 80% path.

Individual commits as well as HISTORY.md have detailed information about the areas targeted, changes involved, and incremental performance improvements.

If you're interested in reviewing this, I would recommend reviewing the changes on a commit by commit basis, guided by the descriptions in each commit.

The work in this branch is event specific.

The intention is to combine this work with the `AttributeCore` and `BaseCore` (event-agnostic) work in https://github.com/sdesai/yui3/tree/attrs-perf, to improve `Attribute`, `Base` and `CustomEvent` times overall.

A separate pull request will be issued for the `attrs-perf` branch.

# Numbers

On Chrome 25, compared to 3.8.1 (and probably 3.9.1), we're seeing the following improvements:

This branch:

Benchmark	x Change

Low-level Publish (over regular publish)	5

Publish	2

Fire With Payload - 10 listeners	2

Fire - 10 listeners	2

Fire With Payload - 2 listeners	2

Fire - 2 listeners	3

Fire With Payload - 0 listeners	6

Fire - 0 listeners	6

EventTarget Construction + Publish(foo) + Fire(foo) - no listeners	3

When combined with the attrs-perf branch, we're seeing:

Benchmark	x Change

new Base()	4

base.set()	4

base.get()	5

Benchmark	x Change

new BaseCore()	3

basecore.set()	3

basecore.get()	4

Safari show a little less, but still significant benefits.
Firefox shows a little less still, but still better than 3.8.1.

# Testing

**All** library tests through `yogi test --no-cli` pass:

`[Total]: Passed: 10731 Failed: 0 Total: 10820 (ignored 89) (7 minutes, 59 seconds)`

Additionally **All** library tests pass on:

* IE8
* Safari6/Mac
* Safari6/iOS6
* FF19
* Chrome26

Aside from a couple of known testing and environment exceptions (jsonp/yeti, datatable date formatting/IE) which also fail on dev-3x.

# Preview And Release Timelines

Given the low-level nature of these changes, and the customizations on top of them, it would be beneficial to get a preview release based on these changes (event-perf-nolisteners + attrs-perf) out and have it get some real-world integration (especially for users with customizations on top of Base), with a week or two of reaction time prior to release, to clean up anything which comes up out of the pull requests and PR.