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

Commit

Permalink
perf(view factory): Remove a try-catch and a timer for the critical path
Browse files Browse the repository at this point in the history
This saves 4% (50ms) in the TreeComponent benchmark.
  • Loading branch information
jbdeboer authored and [email protected] committed May 29, 2014
1 parent 7c9a758 commit 9f4defe
Showing 1 changed file with 28 additions and 34 deletions.
62 changes: 28 additions & 34 deletions lib/core_dom/element_binder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -296,44 +296,38 @@ class ElementBinder {
var nodeAttrs = node is dom.Element ? new NodeAttrs(node) : null;
ElementProbe probe;

var timerId;
assert((timerId = _perf.startTimer('ng.view.link.setUp', _html(node))) != false);
var directiveRefs = _usableDirectiveRefs;
try {
if (!hasDirectivesOrEvents) return parentInjector;

var nodesAttrsDirectives = [];
var nodeModule = new Module()
..bind(NgElement)
..bind(View, toValue: view)
..bind(dom.Element, toValue: node)
..bind(dom.Node, toValue: node)
..bind(NodeAttrs, toValue: nodeAttrs)
..bind(ElementProbe, toFactory: (_) => probe);

directiveRefs.forEach((DirectiveRef ref) {
Directive annotation = ref.annotation;
var visibility = ref.annotation.visibility;
if (ref.annotation is Controller) {
scope = scope.createChild(new PrototypeMap(scope.context));
nodeModule.bind(Scope, toValue: scope);
}
if (!hasDirectivesOrEvents) return parentInjector;

var nodesAttrsDirectives = [];
var nodeModule = new Module()
..bind(NgElement)
..bind(View, toValue: view)
..bind(dom.Element, toValue: node)
..bind(dom.Node, toValue: node)
..bind(NodeAttrs, toValue: nodeAttrs)
..bind(ElementProbe, toFactory: (_) => probe);

directiveRefs.forEach((DirectiveRef ref) {
Directive annotation = ref.annotation;
var visibility = ref.annotation.visibility;
if (ref.annotation is Controller) {
scope = scope.createChild(new PrototypeMap(scope.context));
nodeModule.bind(Scope, toValue: scope);
}

_createDirectiveFactories(ref, nodeModule, node, nodesAttrsDirectives, nodeAttrs,
visibility);
if (ref.annotation.module != null) {
nodeModule.install(ref.annotation.module());
}
});
_createDirectiveFactories(ref, nodeModule, node, nodesAttrsDirectives, nodeAttrs,
visibility);
if (ref.annotation.module != null) {
nodeModule.install(ref.annotation.module());
}
});

_registerViewFactory(node, parentInjector, nodeModule);
_registerViewFactory(node, parentInjector, nodeModule);

nodeInjector = parentInjector.createChild([nodeModule]);
probe = _expando[node] = new ElementProbe(
parentInjector.get(ElementProbe), node, nodeInjector, scope);
} finally {
assert(_perf.stopTimer(timerId) != false);
}
nodeInjector = parentInjector.createChild([nodeModule]);
probe = _expando[node] = new ElementProbe(
parentInjector.get(ElementProbe), node, nodeInjector, scope);

_link(nodeInjector, probe, scope, nodeAttrs, formatters);

Expand Down

0 comments on commit 9f4defe

Please sign in to comment.