perf: improve baseline speed by 30%

Use node.firstChild and node.nextSibling instead 
of node.children or node.childNodes in the baseline
benchmark.
This commit is contained in:
Misko Hevery
2014-12-11 13:58:26 -08:00
parent 017f6ced4d
commit 56b7ba4bce
4 changed files with 19 additions and 10 deletions

View File

@ -191,12 +191,9 @@ function buildTree(maxDepth, values, curDepth) {
buildTree(maxDepth, values, curDepth+1)); buildTree(maxDepth, values, curDepth+1));
} }
var BASELINE_TEMPLATE = DOM.createTemplate(` var BASELINE_TEMPLATE = DOM.createTemplate(
<span> {{}} '<span>_<template class="ng-binding"></template><template class="ng-binding"></template></span>');
<template class="ng-binding"></template> // http://jsperf.com/nextsibling-vs-childnodes
<template class="ng-binding"></template>
</span>`);
class BaseLineTreeComponent { class BaseLineTreeComponent {
element:Element; element:Element;
@ -205,13 +202,16 @@ class BaseLineTreeComponent {
right:BaseLineIf; right:BaseLineIf;
constructor() { constructor() {
this.element = DOM.createElement('span'); this.element = DOM.createElement('span');
var clone = DOM.clone(BASELINE_TEMPLATE.content.children[0]); var clone = DOM.clone(BASELINE_TEMPLATE.content.firstChild);
var shadowRoot = this.element.createShadowRoot(); var shadowRoot = this.element.createShadowRoot();
DOM.appendChild(shadowRoot, clone); DOM.appendChild(shadowRoot, clone);
this.value = new BaseLineInterpolation(clone.childNodes[0]); var child = clone.firstChild;
this.left = new BaseLineIf(clone.children[0]); this.value = new BaseLineInterpolation(child);
this.right = new BaseLineIf(clone.children[1]); child = DOM.nextSibling(child);
this.left = new BaseLineIf(child);
child = DOM.nextSibling(child);
this.right = new BaseLineIf(child);
} }
update(value:TreeNode) { update(value:TreeNode) {
this.value.update(value.value); this.value.update(value.value);

View File

@ -16,3 +16,6 @@ dev_dependencies:
transformers: transformers:
- $dart2js: - $dart2js:
minify: true minify: true
commandLineOptions: [--trust-type-annotations, --trust-primitives, --dump-info]
#commandLineOptions: [--trust-type-annotations, --dump-info]
#commandLineOptions: [--dump-info]

View File

@ -38,6 +38,9 @@ class DOM {
static Node firstChild(el) { static Node firstChild(el) {
return el.firstChild; return el.firstChild;
} }
static Node nextSibling(el) {
return el.nextNode;
}
static Element parentElement(el) { static Element parentElement(el) {
return el.parent; return el.parent;
} }

View File

@ -31,6 +31,9 @@ export class DOM {
static firstChild(el):Node { static firstChild(el):Node {
return el.firstChild; return el.firstChild;
} }
static nextSibling(el):Node {
return el.nextSibling;
}
static parentElement(el) { static parentElement(el) {
return el.parentElement; return el.parentElement;
} }