Skip to content

Commit

Permalink
Passing cfg through to _fireAttrChange, since we already have a refer…
Browse files Browse the repository at this point in the history
…ence

Improves performance for set(), and hence also new Base().

Chrome is pretty much a wash, probably because it's doing something smart
with the function hops.

Testing
-------

All library tests pass:
[Total]: Passed: 10730 Failed: 0 Total: 10819 (ignored 89) (8 minutes, 17 seconds)

Numbers
-------

Chrome 25:

This Commit

Base x 20,433 ops/sec ±1.99% (88 runs sampled)
MyBase x 20,767 ops/sec ±0.65% (97 runs sampled)
MyBase with 10 simple value attributes x 15,255 ops/sec ±1.26% (96 runs sampled)
MyBase with 10 simple value attributes - set x 108,367 ops/sec ±0.83% (91 runs sampled)

Prior Commit

Base x 21,380 ops/sec ±2.20% (91 runs sampled)
MyBase x 20,438 ops/sec ±2.42% (93 runs sampled)
MyBase with 10 simple value attributes x 15,052 ops/sec ±1.62% (92 runs sampled)
MyBase with 10 simple value attributes - set x 103,998 ops/sec ±0.93% (94 runs sampled)

Safari 6:

This Commit

Base x 22,983 ops/sec ±0.46% (68 runs sampled)
MyBase x 21,138 ops/sec ±0.67% (66 runs sampled)
MyBase with 10 simple value attributes x 17,763 ops/sec ±0.74% (66 runs sampled)
MyBase with 10 simple value attributes - set x 88,091 ops/sec ±0.74% (64 runs sampled)

Prior Commit

Base x 18,937 ops/sec ±0.74% (66 runs sampled)
MyBase x 18,192 ops/sec ±0.74% (66 runs sampled)
MyBase with 10 simple value attributes x 15,284 ops/sec ±0.64% (64 runs sampled)
MyBase with 10 simple value attributes - set x 71,233 ops/sec ±0.73% (66 runs sampled)

FF 19:

This Commit

Base x 11,360 ops/sec ±1.31% (86 runs sampled)
MyBase x 11,104 ops/sec ±1.14% (85 runs sampled)
MyBase with 10 simple value attributes x 9,437 ops/sec ±1.30% (90 runs sampled)
MyBase with 10 simple value attributes - set x 52,091 ops/sec ±0.91% (86 runs sampled)

Prior Commit

Base x 10,955 ops/sec ±1.45% (86 runs sampled)
MyBase x 10,762 ops/sec ±1.21% (86 runs sampled)
MyBase with 10 simple value attributes x 9,018 ops/sec ±1.52% (90 runs sampled)
MyBase with 10 simple value attributes - set x 48,555 ops/sec ±0.74% (87 runs sampled)
  • Loading branch information
sdesai committed Mar 22, 2013
1 parent a5a917f commit 839d060
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/attribute/js/AttributeCore.js
Expand Up @@ -507,7 +507,7 @@
} else {
// HACK - no real reason core needs to know about _fireAttrChange, but
// it adds fn hops if we want to break it out. Not sure it's worth it for this critical path
this._fireAttrChange(name, strPath, currVal, val, opts);
this._fireAttrChange(name, strPath, currVal, val, opts, cfg);
}
}
}
Expand Down
15 changes: 9 additions & 6 deletions src/attribute/js/AttributeObservable.js
Expand Up @@ -22,8 +22,7 @@
var EventTarget = Y.EventTarget,

CHANGE = "Change",
BROADCAST = "broadcast",
PUBLISHED = "published";
BROADCAST = "broadcast";

/**
* Provides an augmentable implementation of attribute change events for
Expand Down Expand Up @@ -130,29 +129,33 @@
* @param {Any} newVal The new value of the attribute
* @param {Object} opts Any additional event data to mix into the attribute change event's event facade.
*/
_fireAttrChange : function(attrName, subAttrName, currVal, newVal, opts) {
_fireAttrChange : function(attrName, subAttrName, currVal, newVal, opts, cfg) {
var host = this,
eventName = attrName + CHANGE,
state = host._state,
facade,
broadcast,
evtCfg;

if (!state.get(attrName, PUBLISHED)) {
if (!cfg) {
cfg = state.data[attrName] || {};
}

if (!cfg.published) {

evtCfg = {
defaultTargetOnly: true,
defaultFn:host._defAttrChangeFn
};

broadcast = state.get(attrName, BROADCAST);
broadcast = cfg.broadcast;
if (broadcast !== undefined) {
evtCfg.broadcast = broadcast;
}

host.publish(eventName, evtCfg);

state.add(attrName, PUBLISHED, true);
cfg.published = true;
}

facade = (opts) ? Y.merge(opts) : host._ATTR_E_FACADE;
Expand Down

0 comments on commit 839d060

Please sign in to comment.