brianmhunt / knockout-fast-foreach

Foreach. Faster. For Knockout.
MIT License
59 stars 18 forks source link

What makes fastForEach Faster #48

Closed mshoote closed 7 years ago

mshoote commented 7 years ago

Hi, I was wondering what exactly makes fast for each faster than the normal for each.

I noticed in the .js you mention: "Employing sound techniques to make a faster Knockout foreach binding."

I am not sure if these sound techniques make it faster and if so what are sound techniques?

I am wondering as I am doing a comparison of frameworks and was wondering what made this faster.

brianmhunt commented 7 years ago

Good question. :) There are a few things, including (and I may be forgetting things):

  1. Updates are batched into animationFrames

  2. It has a noIndex option that makes it O(1) in terms of computational complexity

  3. DOM nodes are re-used for re-ordering/deletion/inserts within the same animation frame

  4. It can re-use the Knockout Context with a noContext option

So, in other words, in the average case it'll have fewer reflows because DOM changes are batched into animation frames. When given options noIndex it will scale to relatively huge numbers because each addition has constant-time computational complexity.

I hope that helps explain. (It's also possible I've forgotten something, mind you ...)

mshoote commented 7 years ago

Thank you for the response! That helps a lot.

krnlde commented 7 years ago

So this issue can be closed?

mshoote commented 7 years ago

Yes this issue can be closed.