Skip to content

Commit

Permalink
performance improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
justinbmeyer authored and daffl committed Jun 10, 2014
1 parent 4aa9f47 commit d770ca6
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 8 deletions.
6 changes: 3 additions & 3 deletions map/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ steal('can/util', 'can/util/bind','./bubble.js', 'can/construct', 'can/util/batc
return [attr];
}
// Split key on '.'
return can.isArray(attr) ? attr : ("" + attr)
return typeof attr === "object" ? attr : ("" + attr)
.split(".");
},
/**
Expand Down Expand Up @@ -336,7 +336,6 @@ steal('can/util', 'can/util/bind','./bubble.js', 'can/construct', 'can/util/batc
return this._attrs(attr, val);
// If we are getting a value.
} else if (arguments.length === 1) {
// Let people know we are reading.
can.__reading(this, attr);
return this._get(attr);
} else {
Expand Down Expand Up @@ -390,6 +389,7 @@ steal('can/util', 'can/util/bind','./bubble.js', 'can/construct', 'can/util/batc
},
// Reads a property from the `object`.
_get: function (attr) {

var value;

// Handles the case of a key having a `.` in its name
Expand Down Expand Up @@ -510,7 +510,7 @@ steal('can/util', 'can/util/bind','./bubble.js', 'can/construct', 'can/util/batc
}
// Add property directly for easy writing.
// Check if its on the `prototype` so we don't overwrite methods like `attrs`.
if (! typeof this.constructor.prototype[prop] === 'function' && !this._computedBindings[prop] ) {
if ( typeof this.constructor.prototype[prop] !== 'function' && !this._computedBindings[prop] ) {
this[prop] = val;
}
},
Expand Down
4 changes: 2 additions & 2 deletions map/map_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ steal("can/map", "can/compute", "can/test", "can/list", function(){
});
state.removeAttr("key.with.dots");
state2.removeAttr("key.with.someValue");
deepEqual(can.Map.keys(state), ["productType"], "one property");
deepEqual(can.Map.keys(state2), ["key.with.dots", "key"], "two properties");
deepEqual( can.Map.keys(state), ["productType"], "one property");
deepEqual( can.Map.keys(state2), ["key.with.dots", "key"], "two properties");
deepEqual( can.Map.keys( state2.key["with"] ) , [], "zero properties");
});

Expand Down
2 changes: 1 addition & 1 deletion map/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ <h2 id="qunit-userAgent"></h2>
can.dev.logLevel = 3;
QUnit.start();
});
},300);
},400);

</script>
</body>
Expand Down
2 changes: 2 additions & 0 deletions view/scope/scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ steal(
rootReads = data.reads;
computeData.scope = data.scope;
computeData.initialValue = data.value;
computeData.reads = data.reads;
computeData.root = rootObserve;
return data.value;
}
})
Expand Down
8 changes: 8 additions & 0 deletions view/stache/mustache_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,12 @@ steal("can/util",
compute = computeData.compute;

initialValue = computeData.initialValue;
if(computeData.reads && computeData.reads.length === 1 && computeData.root instanceof can.Map) {
console.log("fast")
//can.compute(computeData.root, computeData.reads[0])
}


// Set name to be the compute if the compute reads observables,
// or the value of the value of the compute if no observables are found.
if(computeData.compute.hasDependencies) {
Expand Down Expand Up @@ -309,6 +315,7 @@ steal("can/util",
return function(){
return name();
};

}
// Just return name as the value
else {
Expand Down Expand Up @@ -396,6 +403,7 @@ steal("can/util",
return function branchRenderer(scope, options, truthyRenderer, falseyRenderer){
// TODO: What happens if same mode/expresion, but different sub-sections?
// Check the scope's cache if the evaluator already exists for performance.
//console.log("here!");
var evaluator = scope.__cache[fullExpression];
if(!evaluator) {
evaluator = scope.__cache[fullExpression] = makeEvaluator( scope, options, mode, exprData, truthyRenderer, falseyRenderer, true);
Expand Down
5 changes: 3 additions & 2 deletions view/stache/visual_benchmark.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@
}
});

for(var i =0; i < 100; i++) {
for(var i =0; i < 1; i++) {
var box = new Box({ number: i });
box.tick();
boxes.push( box );
}

Expand Down Expand Up @@ -126,7 +127,7 @@
if (loopCount % 20 === 0) {
$('#timing').text('Performed ' + loopCount + ' iterations in ' + totalTime + ' ms (average ' + (totalTime / loopCount).toFixed(2) + ' ms per loop).');
}
if(loopCount < 1000) {
if(loopCount < 0) {
timeout = setTimeout(function(){
benchmarkLoop(fn);
},1);
Expand Down

0 comments on commit d770ca6

Please sign in to comment.