Skip to content

Commit 56b7ba4

Browse files
committed
perf: improve baseline speed by 30%
Use node.firstChild and node.nextSibling instead of node.children or node.childNodes in the baseline benchmark.
1 parent 017f6ce commit 56b7ba4

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

modules/benchmarks/src/tree/tree_benchmark.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,9 @@ function buildTree(maxDepth, values, curDepth) {
191191
buildTree(maxDepth, values, curDepth+1));
192192
}
193193

194-
var BASELINE_TEMPLATE = DOM.createTemplate(`
195-
<span> {{}}
196-
<template class="ng-binding"></template>
197-
<template class="ng-binding"></template>
198-
</span>`);
199-
194+
var BASELINE_TEMPLATE = DOM.createTemplate(
195+
'<span>_<template class="ng-binding"></template><template class="ng-binding"></template></span>');
196+
// http://jsperf.com/nextsibling-vs-childnodes
200197

201198
class BaseLineTreeComponent {
202199
element:Element;
@@ -205,13 +202,16 @@ class BaseLineTreeComponent {
205202
right:BaseLineIf;
206203
constructor() {
207204
this.element = DOM.createElement('span');
208-
var clone = DOM.clone(BASELINE_TEMPLATE.content.children[0]);
205+
var clone = DOM.clone(BASELINE_TEMPLATE.content.firstChild);
209206
var shadowRoot = this.element.createShadowRoot();
210207
DOM.appendChild(shadowRoot, clone);
211208

212-
this.value = new BaseLineInterpolation(clone.childNodes[0]);
213-
this.left = new BaseLineIf(clone.children[0]);
214-
this.right = new BaseLineIf(clone.children[1]);
209+
var child = clone.firstChild;
210+
this.value = new BaseLineInterpolation(child);
211+
child = DOM.nextSibling(child);
212+
this.left = new BaseLineIf(child);
213+
child = DOM.nextSibling(child);
214+
this.right = new BaseLineIf(child);
215215
}
216216
update(value:TreeNode) {
217217
this.value.update(value.value);

modules/examples/pubspec.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ dev_dependencies:
1616
transformers:
1717
- $dart2js:
1818
minify: true
19+
commandLineOptions: [--trust-type-annotations, --trust-primitives, --dump-info]
20+
#commandLineOptions: [--trust-type-annotations, --dump-info]
21+
#commandLineOptions: [--dump-info]

modules/facade/src/dom.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ class DOM {
3838
static Node firstChild(el) {
3939
return el.firstChild;
4040
}
41+
static Node nextSibling(el) {
42+
return el.nextNode;
43+
}
4144
static Element parentElement(el) {
4245
return el.parent;
4346
}

modules/facade/src/dom.es6

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ export class DOM {
3131
static firstChild(el):Node {
3232
return el.firstChild;
3333
}
34+
static nextSibling(el):Node {
35+
return el.nextSibling;
36+
}
3437
static parentElement(el) {
3538
return el.parentElement;
3639
}

0 commit comments

Comments
 (0)