2 ms·
React is not optimal, or it would require O(N^3) time at least. Think for example of a linear structure like a listbox, and then consider that a perfect diff re
by amelius 10y ago
React is not optimal, or it would require O(N^3) time at least. Think for example of a linear structure like a listbox, and then consider that a perfect diff requires an algorithm like Smith-Waterman, which is O(N^3). (Perhaps faster algorithms exist, but they are probably not really significantly faster).
- Etzos 10y agoI certainly wasn't commenting on the preciseness of React's diffing (and how they're able to reduce it from O(n) to O(n^3) by ignoring things). I was merely pointing out that it's possible to diff trees in polynomial time. Edit: Just to clarity, I'm also not saying O(n^3) isn't slow compared to React's O(n), just that it's potentially a lot faster than NP.