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));
}
var BASELINE_TEMPLATE = DOM.createTemplate(`
<span> {{}}
<template class="ng-binding"></template>
<template class="ng-binding"></template>
</span>`);
var BASELINE_TEMPLATE = DOM.createTemplate(
'<span>_<template class="ng-binding"></template><template class="ng-binding"></template></span>');
// http://jsperf.com/nextsibling-vs-childnodes
class BaseLineTreeComponent {
element:Element;
@ -205,13 +202,16 @@ class BaseLineTreeComponent {
right:BaseLineIf;
constructor() {
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();
DOM.appendChild(shadowRoot, clone);
this.value = new BaseLineInterpolation(clone.childNodes[0]);
this.left = new BaseLineIf(clone.children[0]);
this.right = new BaseLineIf(clone.children[1]);
var child = clone.firstChild;
this.value = new BaseLineInterpolation(child);
child = DOM.nextSibling(child);
this.left = new BaseLineIf(child);
child = DOM.nextSibling(child);
this.right = new BaseLineIf(child);
}
update(value:TreeNode) {
this.value.update(value.value);

View File

@ -16,3 +16,6 @@ dev_dependencies:
transformers:
- $dart2js:
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) {
return el.firstChild;
}
static Node nextSibling(el) {
return el.nextNode;
}
static Element parentElement(el) {
return el.parent;
}

View File

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