lui
lui copied to clipboard
Smarter reordering algorithm
IS
~~Currently, node_map items are ordered by reinserting them when their index (absolute position) has changed.~~
~~Currently, node_map items are ordered by reinserting all of them.~~
Currently, node_map items are ordered by reinserting all of them if their nextSibling changes.
SHOULD
~~Just reinsert them if their relative position has changed!~~ Try to reinsert as fewest as possible without getting too complicated.
Note
In practice, it works well enough. But as shown by benchmark, this makes lui one of the slowest candidates for "remove row", since all n rows get reinserted without any need. It just looks bad in the table!
The index-based method was pretty stable in most cases but in some rare cases, the reordering would have been incorrect, so I went for a temporary and much less efficient solution: Reinserting all items on each rerender.