From 56b7ba4bce516f6fab686e3af78753139275e1cd Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 11 Dec 2014 13:58:26 -0800 Subject: [PATCH] perf: improve baseline speed by 30% Use node.firstChild and node.nextSibling instead of node.children or node.childNodes in the baseline benchmark. --- modules/benchmarks/src/tree/tree_benchmark.js | 20 +++++++++---------- modules/examples/pubspec.yaml | 3 +++ modules/facade/src/dom.dart | 3 +++ modules/facade/src/dom.es6 | 3 +++ 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/modules/benchmarks/src/tree/tree_benchmark.js b/modules/benchmarks/src/tree/tree_benchmark.js index b4284df5ff..4f357b39f9 100644 --- a/modules/benchmarks/src/tree/tree_benchmark.js +++ b/modules/benchmarks/src/tree/tree_benchmark.js @@ -191,12 +191,9 @@ function buildTree(maxDepth, values, curDepth) { buildTree(maxDepth, values, curDepth+1)); } -var BASELINE_TEMPLATE = DOM.createTemplate(` - {{}} - - - `); - +var BASELINE_TEMPLATE = DOM.createTemplate( + '_'); +// 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); diff --git a/modules/examples/pubspec.yaml b/modules/examples/pubspec.yaml index 6c8ace8da7..1d32151ec0 100644 --- a/modules/examples/pubspec.yaml +++ b/modules/examples/pubspec.yaml @@ -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] \ No newline at end of file diff --git a/modules/facade/src/dom.dart b/modules/facade/src/dom.dart index 9e25dadc4e..b1ff4cd479 100644 --- a/modules/facade/src/dom.dart +++ b/modules/facade/src/dom.dart @@ -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; } diff --git a/modules/facade/src/dom.es6 b/modules/facade/src/dom.es6 index f1013f2222..34fccae5fd 100644 --- a/modules/facade/src/dom.es6 +++ b/modules/facade/src/dom.es6 @@ -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; }