Skip to content

Commit

Permalink
improve performance, update benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
mbasso committed May 22, 2018
1 parent 0191265 commit 7d87523
Show file tree
Hide file tree
Showing 20 changed files with 50 additions and 42 deletions.
16 changes: 14 additions & 2 deletions benchmarks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ There are 4 tests at the moment:

- `add/remove nodes`: this test runs the `patch` function 100 times with 2 nodes, one with 100 children and one without children.

Here you can find screenshots of the tests (lower is better) runned on a MacBook Pro (Retina, 13-inch, Late 2013), Processor 2,4 GHz Intel Core i5, Memory 8 GB 1600 MHz DDR3:
Here you can find the tests (lower is better) runned on a MacBook Pro (Retina, 13-inch, Late 2013), Processor 2,4 GHz Intel Core i5, Memory 8 GB 1600 MHz DDR3:

![Benchmarks](benchmarks.jpg)
### Firefox 59.0.2 (64 bit)

| library | create nodes | diff equal nodes | diff different nodes | add/remove nodes |
| --- | --- | --- | --- | --- |
| asm-dom | 0.0000 | 2.0000 | 34.0000 | 32.0000 |
| snabbbom | 0.0000 | 12.0000 | 42.0000 | 44.0000 |

### Chrome 66.0.3359.181 (64-bit)

| library | create nodes | diff equal nodes | diff different nodes | add/remove nodes |
| --- | --- | --- | --- | --- |
| asm-dom | 0.9000 | 3.2000 | 16.4000 | 15.1000 |
| snabbbom | 0.5000 | 4.6000 | 8.7000 | 13.3000 |
Binary file removed benchmarks/benchmarks.jpg
Binary file not shown.
Binary file modified benchmarks/compiled/app.bc
Binary file not shown.
10 changes: 5 additions & 5 deletions benchmarks/compiled/asmjs/app.asm.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions benchmarks/compiled/wasm/app.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified benchmarks/compiled/wasm/app.wasm
Binary file not shown.
Binary file modified compiled/asm-dom.a
Binary file not shown.
Binary file modified compiled/asm-dom.bc
Binary file not shown.
Binary file modified compiled/asm-dom.o
Binary file not shown.
8 changes: 4 additions & 4 deletions compiled/asmjs/asm-dom.asm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion compiled/wasm/asm-dom.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified compiled/wasm/asm-dom.wasm
Binary file not shown.
24 changes: 11 additions & 13 deletions cpp/Patch/patch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace asmdom {
bool sameVNode(const VNode* __restrict__ const vnode1, const VNode* __restrict__ const vnode2) {
return
// compare selector, nodeType and key existance
(vnode1->hash & id) == (vnode2->hash & id) &&
((vnode1->hash & id) == (vnode2->hash & id)) &
// compare keys
(!(vnode1->hash & hasKey) || vnode1->key == vnode2->key);
};
Expand Down Expand Up @@ -86,12 +86,9 @@ namespace asmdom {
const std::vector<VNode*>::size_type endIdx
) {
while (startIdx <= endIdx) {
VNode* const vnode = vnodes[startIdx++];
if (vnode) {
EM_ASM_({
Module.insertBefore($0, $1, $2)
}, parentElm, createElm(vnode), before);
}
EM_ASM_({
Module.insertBefore($0, $1, $2)
}, parentElm, createElm(vnodes[startIdx++]), before);
}
};

Expand All @@ -104,18 +101,19 @@ namespace asmdom {
VNode* const vnode = vnodes[startIdx++];

if (vnode) {
EM_ASM_({
Module.removeChild($0);
}, vnode->elm);

#ifdef ASMDOM_JS_SIDE
EM_ASM_({
var data = window['asmDomHelpers']['vnodesData'][$0];
Module.removeChild($0);
var data = window['asmDomHelpers']['vnodesData'][$1];
if (data !== undefined && data['ref'] !== undefined) {
data['ref'](null);
}
}, reinterpret_cast<std::uintptr_t>(vnode));
}, vnode->elm, reinterpret_cast<std::uintptr_t>(vnode));
#else
EM_ASM_({
Module.removeChild($0);
}, vnode->elm);

if (vnode->hash & hasRef) {
vnode->data.callbacks["ref"](
emscripten::val::null()
Expand Down
2 changes: 1 addition & 1 deletion dist/js/0.asm-dom.js

Large diffs are not rendered by default.

Binary file modified dist/js/0.asm-dom.js.br
Binary file not shown.
Binary file modified dist/js/0.asm-dom.js.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/js/1.asm-dom.js

Large diffs are not rendered by default.

Binary file modified dist/js/1.asm-dom.js.br
Binary file not shown.
Binary file modified dist/js/1.asm-dom.js.gz
Binary file not shown.
24 changes: 11 additions & 13 deletions src/cpp/Patch/patch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace asmdom {
bool sameVNode(const VNode* __restrict__ const vnode1, const VNode* __restrict__ const vnode2) {
return
// compare selector, nodeType and key existance
(vnode1->hash & id) == (vnode2->hash & id) &&
((vnode1->hash & id) == (vnode2->hash & id)) &
// compare keys
(!(vnode1->hash & hasKey) || vnode1->key == vnode2->key);
};
Expand Down Expand Up @@ -86,12 +86,9 @@ namespace asmdom {
const std::vector<VNode*>::size_type endIdx
) {
while (startIdx <= endIdx) {
VNode* const vnode = vnodes[startIdx++];
if (vnode) {
EM_ASM_({
Module.insertBefore($0, $1, $2)
}, parentElm, createElm(vnode), before);
}
EM_ASM_({
Module.insertBefore($0, $1, $2)
}, parentElm, createElm(vnodes[startIdx++]), before);
}
};

Expand All @@ -104,18 +101,19 @@ namespace asmdom {
VNode* const vnode = vnodes[startIdx++];

if (vnode) {
EM_ASM_({
Module.removeChild($0);
}, vnode->elm);

#ifdef ASMDOM_JS_SIDE
EM_ASM_({
var data = window['asmDomHelpers']['vnodesData'][$0];
Module.removeChild($0);
var data = window['asmDomHelpers']['vnodesData'][$1];
if (data !== undefined && data['ref'] !== undefined) {
data['ref'](null);
}
}, reinterpret_cast<std::uintptr_t>(vnode));
}, vnode->elm, reinterpret_cast<std::uintptr_t>(vnode));
#else
EM_ASM_({
Module.removeChild($0);
}, vnode->elm);

if (vnode->hash & hasRef) {
vnode->data.callbacks["ref"](
emscripten::val::null()
Expand Down

0 comments on commit 7d87523

Please sign in to comment.