Repository navigation
Conversation
With the default diff, diffArrays now checks whether two items are equal with a dedicated equalAny instead of !diff(a, b, ptr).length, which built the whole nested diff (paths included) only to check that it was empty. equalAny follows the current rules of diffAny/diffObjects and stops at the first difference. A custom diff is still asked, so chbrown#15 is unaffected. Co-Authored-By: Claude Opus 5.5 <[email protected]>
With the default diff, diffArrays now checks whether two elements are equal with isEqual, which gives the same answer as !diffAny(...).length but stops at the first difference and builds no operations or pointers. A custom diff is still called, since it may consider elements equal that isEqual wouldn't (#15). equalAtomic now takes an equality callback, so the Date/Map/Set rules are shared by diffAny and isEqual. Based on the early-exit idea from #103 and indepedently matches implementation in #117 (our Claudes think alike ;)). Coded by Claude, who lacks a real email address. Co-Authored-By: Vico <[email protected]> Co-Authored-By: Josh Kelley <[email protected]>
|
Haha I was just working (/ having my Claude work) on this, this morning, and came up with basically the same final step (atop others) as your change here. Sorry! Great (Claude Opus 5.5) minds think alike, I guess. 4cedb42 obsoletes this, and builds on other improvements that make |
|
Anyway, thanks, closing this, but feel free to open another PR with further improvements like whatever the docmost repo is doing. There's now a benchmark directory in master that'd be useful to compare with. |
|
I’ll leave you to continue working on the development. There’s some optimization to be gained by using the Ukkonen/Myers algorithm for the diff, similar to how it’s done in Docmost. Happy coding! |
This is the "exit at the first inequality" idea @joshkel proposed in #103, split out as asked, without
fast-deep-equal: no new dependency, and the current equality rules are kept (undefinedkeys,NaN,Dates), so the patches don't change.With the default diff,
diffArraysnow compares items with a privateequalAnyinstead of!diff(a, b, ptr).length, which built the whole nested diff only to check it was empty (theTODOfrom bb8c99b). A customdiffis still asked, so #15 is unaffected.createPatch, depending on the size and nesting of the array items (e.g. a 120-paragraph ProseMirror doc: 39 ms → 3.2 ms).The quadratic cost on long arrays remains; docmost/docmost#2689 has a banded (Ukkonen-style) version with identical patches in my tests, and I'm asking its author about upstreaming it.