Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faster mounting #36

Merged
merged 3 commits into from
Aug 25, 2016
Merged

Faster mounting #36

merged 3 commits into from
Aug 25, 2016

Conversation

maciejhirsz
Copy link
Contributor

  • Use child.constructor to tests for built in types: String, Number and Array
  • Reordered to return early for all the types above.
  • Identify instances of Node by checking the built in Node#nodeType integer instead of using instanceof, avoiding traversing the prototype inheritance chain.
  • Super minor: moved mounted / remounted calls behind the check for child being a bare Node. Benefits are close to none, but the cost in complexity is zero, so why not.

Code tested:

div(
    h1({ 'class': 'frzr' }, 'Hello ', b('FRZR'), '!'),
    p('Bacon ipsum dolor amet meatloaf meatball shank porchetta \
        picanha bresaola short loin short ribs capicola fatback beef \
        ribs corned beef ham hock.')
);

Before:

Benching FRZR <div> with multiple child nodes
29960ns per iteration (33377 ops/sec)

After:

Benching FRZR <div> with multiple child nodes
13010ns per iteration (76862 ops/sec)

VanillaJS with innerHTML to compare:

var div = document.createElement('div');
div.innerHTML = '<h1 class="frzr">Hello <b>FRZR</b>!</h1>\
<p>\
    Bacon ipsum dolor amet meatloaf meatball shank porchetta \
    picanha bresaola short loin short ribs capicola fatback beef \
    ribs corned beef ham hock.\
</p>';
Benching Vanilla JS innerHTML
build.js:19 - 23341ns per iteration (42843 ops/sec)

Tried to not add any amount of code that isn't strictly necessary, there is +9 lines but some of those are whitespace :).

@maciejhirsz
Copy link
Contributor Author

Also #35

@pakastin
Copy link
Owner

Wow, you're on fire! ⚡️

@pakastin
Copy link
Owner

Good stuff! That trick of checking the constructor is especially brilliant. 👍

@pakastin pakastin merged commit 6905602 into pakastin:master Aug 25, 2016
pakastin added a commit that referenced this pull request Aug 25, 2016
@pakastin
Copy link
Owner

Released, thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants