Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit 6062610

Browse files
jbdeboertravis@travis-ci.org
authored andcommitted
perf(view factory): Remove try-finally from ElementBinder._link
This saves 9% of the runtime in the TreeComponent benchmark.
1 parent 9f4defe commit 6062610

File tree

1 file changed

+24
-34
lines changed

1 file changed

+24
-34
lines changed

Diff for: lib/core_dom/element_binder.dart

+24-34
Original file line numberDiff line numberDiff line change
@@ -203,46 +203,36 @@ class ElementBinder {
203203

204204
void _link(nodeInjector, probe, scope, nodeAttrs, formatters) {
205205
_usableDirectiveRefs.forEach((DirectiveRef ref) {
206-
var linkTimer;
207-
try {
208-
var linkMapTimer;
209-
assert((linkTimer = _perf.startTimer('ng.view.link', ref.type)) != false);
210-
var directive = nodeInjector.get(ref.type);
211-
probe.directives.add(directive);
212-
assert((linkMapTimer = _perf.startTimer('ng.view.link.map', ref.type)) != false);
213-
214-
if (ref.annotation is Controller) {
215-
scope.context[(ref.annotation as Controller).publishAs] = directive;
216-
}
206+
var directive = nodeInjector.get(ref.type);
207+
probe.directives.add(directive);
217208

218-
var tasks = new _TaskList(directive is AttachAware ? () {
219-
if (scope.isAttached) directive.attach();
220-
} : null);
209+
if (ref.annotation is Controller) {
210+
scope.context[(ref.annotation as Controller).publishAs] = directive;
211+
}
221212

222-
if (ref.mappings.isNotEmpty) {
223-
if (nodeAttrs == null) nodeAttrs = new _AnchorAttrs(ref);
224-
_createAttrMappings(directive, scope, ref.mappings, nodeAttrs, formatters, tasks);
225-
}
213+
var tasks = new _TaskList(directive is AttachAware ? () {
214+
if (scope.isAttached) directive.attach();
215+
} : null);
226216

227-
if (directive is AttachAware) {
228-
var taskId = tasks.registerTask();
229-
Watch watch;
230-
watch = scope.watch('1', // Cheat a bit.
231-
(_, __) {
232-
watch.remove();
233-
tasks.completeTask(taskId);
234-
});
235-
}
217+
if (ref.mappings.isNotEmpty) {
218+
if (nodeAttrs == null) nodeAttrs = new _AnchorAttrs(ref);
219+
_createAttrMappings(directive, scope, ref.mappings, nodeAttrs, formatters, tasks);
220+
}
236221

237-
tasks.doneRegistering();
222+
if (directive is AttachAware) {
223+
var taskId = tasks.registerTask();
224+
Watch watch;
225+
watch = scope.watch('1', // Cheat a bit.
226+
(_, __) {
227+
watch.remove();
228+
tasks.completeTask(taskId);
229+
});
230+
}
238231

239-
if (directive is DetachAware) {
240-
scope.on(ScopeEvent.DESTROY).listen((_) => directive.detach());
241-
}
232+
tasks.doneRegistering();
242233

243-
assert(_perf.stopTimer(linkMapTimer) != false);
244-
} finally {
245-
assert(_perf.stopTimer(linkTimer) != false);
234+
if (directive is DetachAware) {
235+
scope.on(ScopeEvent.DESTROY).listen((_) => directive.detach());
246236
}
247237
});
248238
}

0 commit comments

Comments
 (0)