Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 9ae0c01

Browse files
jbedardlgalfaso
authored andcommitted
perf($compile): only re-$interpolate attribute values at link time if changed since compile
1 parent 79b3b8b commit 9ae0c01

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

benchmarks/largetable-bp/main.html

+7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<div>ngBind: <input type="radio" ng-model="benchmarkType" value="ngBind"></div>
1515
<div>ngBindOnce: <input type="radio" ng-model="benchmarkType" value="ngBindOnce"></div>
1616
<div>interpolation: <input type="radio" ng-model="benchmarkType" value="interpolation"></div>
17+
<div>attribute interpolation: <input type="radio" ng-model="benchmarkType" value="interpolationAttr"></div>
1718
<div>ngBind + fnInvocation: <input type="radio" ng-model="benchmarkType" value="ngBindFn"></div>
1819
<div>interpolation + fnInvocation: <input type="radio" ng-model="benchmarkType" value="interpolationFn"></div>
1920
<div>ngBind + filter: <input type="radio" ng-model="benchmarkType" value="ngBindFilter"></div>
@@ -46,6 +47,12 @@ <h2>baseline interpolation</h2>
4647
<span ng-repeat="column in row">{{column.i}}:{{column.j}}|</span>
4748
</div>
4849
</div>
50+
<div ng-switch-when="interpolationAttr">
51+
<h2>attribute interpolation</h2>
52+
<div ng-repeat="row in data">
53+
<span ng-repeat="column in row" i="{{column.i}}" j="{{column.j}}">i,j attrs</span>
54+
</div>
55+
</div>
4956
<div ng-switch-when="ngBindFn">
5057
<h2>bindings with functions</h2>
5158
<div ng-repeat="row in data">

src/ng/compile.js

+12-9
Original file line numberDiff line numberDiff line change
@@ -2335,7 +2335,10 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
23352335

23362336

23372337
function addAttrInterpolateDirective(node, directives, value, name, allOrNothing) {
2338-
var interpolateFn = $interpolate(value, true);
2338+
var trustedContext = getTrustedContext(node, name);
2339+
allOrNothing = ALL_OR_NOTHING_ATTRS[name] || allOrNothing;
2340+
2341+
var interpolateFn = $interpolate(value, true, trustedContext, allOrNothing);
23392342

23402343
// no interpolation found -> ignore
23412344
if (!interpolateFn) return;
@@ -2360,16 +2363,16 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
23602363
"ng- versions (such as ng-click instead of onclick) instead.");
23612364
}
23622365

2363-
// If the attribute was removed, then we are done
2364-
if (!attr[name]) {
2365-
return;
2366+
// If the attribute has changed since last $interpolate()ed
2367+
var newValue = attr[name];
2368+
if (newValue !== value) {
2369+
// we need to interpolate again since the attribute value has been updated
2370+
// (e.g. by another directive's compile function)
2371+
// ensure unset/empty values make interpolateFn falsy
2372+
interpolateFn = newValue && $interpolate(newValue, true, trustedContext, allOrNothing);
2373+
value = newValue;
23662374
}
23672375

2368-
// we need to interpolate again, in case the attribute value has been updated
2369-
// (e.g. by another directive's compile function)
2370-
interpolateFn = $interpolate(attr[name], true, getTrustedContext(node, name),
2371-
ALL_OR_NOTHING_ATTRS[name] || allOrNothing);
2372-
23732376
// if attribute was updated so that there is no interpolation going on we don't want to
23742377
// register any observers
23752378
if (!interpolateFn) return;

0 commit comments

Comments
 (0)