jsondiffpatch icon indicating copy to clipboard operation
jsondiffpatch copied to clipboard

Performance analysis of jsondiffpatch

Open guelzimtr opened this issue 11 years ago • 5 comments

Hello,

is there any known study of the library performance. I am using it for a project and i notice that starting 3000 nodes in a json array, the diff would takes 3 ,6 seconds... etc

Are there any performance tips to use. maybe a heuristic algorithm to prevent visiting nodes that would "not likely" unmatch ?

Thanks

guelzimtr avatar Sep 07 '14 20:09 guelzimtr

Another addition. when the size of the left object > 10K nodes and right object ~5K nodes, i get the error RangeError: Maximum call stack size exceeded casused by the match function

guelzimtr avatar Sep 07 '14 23:09 guelzimtr

hi, unfortunately, no, I never did any serious performance or load tests, part of the reason is the scenarios I've thought this for are about synchronizing user edits in realtime, where the size of the json document is limited by the amount of info you can reasonably show in the screen. But I'm interested in those results, and wouldn't mind doing adjustments (as soon as it doesn't introduces lots of complexity or big refactorings, eg. I bet a C/C++ lib compiled with emscripten could probably be the most performant option). Regarding documents with lots of nodes, but few changes, there are some optimizations that you could to avoid re-comparing every time, if you can detect the changes in a more performant way:

  • because you control the UI (so you know exactly when and where changes are introduced), or
  • you use some sort of change tracking (eg. Object.observe or something like knockout.js)

Then, you can save some special flag on nodes (eg. __hasChanges), and create a jsondiffpatch plugin to look for that flag before trying a deep comparison (check /docs/plugins.md for instructions on how to create plugins)

re. the call stack size error, in general jsondiffpatch uses a js array as stack instead of function recursion to prevent that, but there might be a spot I missed, if you have a reproducible case or a stack trace I can try removing recursion.

benjamine avatar Sep 08 '14 13:09 benjamine

Hi there, i plan to use a diffing algorithm for a custom mvc framework i have and want to ask same question about performance.

i study both jsondiffpath and objectDiff for object/array diffing.

The use case is when an model object or collection (i.e array most used case) changes the mcv should make only the necessary dom changes. This is fine, but model changes may happen many times and on many data so for good lice dom performance the performance of the diffing algorithm is important.

Thanks

foo123 avatar Oct 21 '14 20:10 foo123

@foo123 Sounds quite intereting. I'm trying to do something like that too but now I'm wondering if another solution can more efficient if I transform data into JSON text as diff them by lines..

tiye avatar Nov 09 '14 16:11 tiye

@benjamine
Hi. Thanks for the great library. It would be great if you could post complexity estimates in README. I guess a lot of people need to know what speed they should expect from algorithm.

pmapcat avatar Aug 22 '15 14:08 pmapcat