yui/yui3 — pull request #863 by sdesai (2013-06-12 18:33:22+00:00)
Title: Base `init` and Attribute change events bypass Event system, if no listeners present

See:

https://github.com/yui/yui3/issues/702
https://github.com/yui/yui3/pull/572#issuecomment-15808262

This is a somewhat hacky attempt to improve performance for the common use case where Base's `init` event and Attribute change events in general, don't have any listeners.

The idea is to get Base runtime performance closer to BaseCore, when no listeners exist [ essentially making observability closer to zero runtime cost, if it's not being used ].

The only remaining hackiness, after a cleanup pass I did, is really due to Base having to work with CustomEvent internals for the fireOnce init event. I'm happy with the Attribute change solution.

## Model Changes

Needed to change Model's override of `_defAttrChangeFn`, in order to remove one of the 2 hacky pieces in Base/Attribute, and change it to override `_setAttrVal` instead to support it's coalesced change event support. Both of these methods are currently private, and should probably remain so.

In general the coalesced change support, and a large part of what Model does with attribute change events could effectively be in an Attribute extension (that is, you may want that same coalesced change functionality for anything Attribute based) so I'm fine with this coupling for now. Ideally we should move it into an Attribute extension, sitting closer to the Attribute code anyway.

## Numbers

Performance improvements are in the thread mentioned above, and are pretty significant (`set` operations showed 4x improvement, over 3.10.0 in the case of no listeners - making a 16x improvement over 3.9.0 overall), but I'll re-run them with current code and post them.

## Testing

Tests are coming, for Base init and Attribute change events with/without listeners, as well as the new CustomEvent methods, but wanted to get this out there for review sooner rather than later.

**All** current unit tests pass, which is the main indicator of quality I've been using:
✔ [Total]: Passed: 11009 Failed: 0 Total: 11100 (ignored 91)

## Preview Release

This pull request along with https://github.com/yui/yui3/pull/781 both have the potential to impact real-world customizations, although it's expected to be rare.

Getting them out in a Preview Release, early in the release is important, along with adoption of this release, to see if there are real world issues which would cause us to back off from these changes.