crysalead-js / dom-layer

Virtual DOM implementation.
MIT License
30 stars 1 forks source link

optimize #57

Closed ghost closed 9 years ago

ghost commented 9 years ago

Hi. I'm new in this. Sorry. But I like challenges. This paldepind can't be so smart. The code you took from him. Localvoid, react etc have a function called movechild (). Append Child and not insert before if the second argument are 0. Better performance.

For nextsibling. There is nothing after end. So end will be start point. Use append child.

Check against === undefined are slow. None of the libs do that.

Quick bail out if no children and no iteration They do.

And if only 1 child they deal with it without iteration.

jails commented 9 years ago

Hi. I'm new in this. Sorry. But I like challenges. This paldepind can't be so smart. The code you took from him. Localvoid, react etc have a function called movechild (). Append Child and not insert before if the second argument are 0. Better performance.

Not sure to get what you mean here.

For nextsibling. There is nothing after end. So end will be start point. Use append child.

insertBefore() acts as appendChild() when nextSibling is null, so I see no reason to complexify the code by adding an additionnal if since the result will be the same.

Check against === undefined are slow. None of the libs do that.

delete is slow but === undefined is not slower as any other comparison afaik.

Quick bail out if no children and no iteration They do. And if only 1 child they deal with it without iteration.

snabbdom reach better performances than all others implementations, so I'm not worried too much about the algorithm itself. Micro optimisations are most of the time imperceptibles. And the price to pay on a codebase is on the contrary not negligible.

Anyhow you can open a PR if you have something better in mind ;-)