google / incremental-dom

An in-place DOM diffing library
http://google.github.io/incremental-dom/
Apache License 2.0
3.54k stars 180 forks source link

Optimize with a monotonic increasing typeId #330

Closed jridgewell closed 6 years ago

jridgewell commented 7 years ago

This has the interesting optimizations from #307, including:

  1. Will remove elements with lower typeIds when considering the next node to align with.
    • Say we have elements 1, 2, 3, and we pass in 2. We know we can pop off 1 without further consideration (typeId is lower).
  2. Will scan ahead elements when considering if there is a matching node, similar to key
    • Say we have elements div-1, span-1, div-3, and we pass in span-1. We can't pop div-1 off just yet, because typeId is not lower. But we can scan ahead for similar typeIds (until with hit the 3) to see if a matching element is ahead.
  3. Will insert a lower typeId immediately, expecting higher ones to come.
    • Say we have just 2, and we pass in 1, 2. Because 2 is higher than our 1, we know we can insert immediately. Now when the 2 comes in second, we get a match.

Closes https://github.com/google/incremental-dom/issues/307.