jsondiffpatch icon indicating copy to clipboard operation
jsondiffpatch copied to clipboard

Request: Merging deltas

Open peter-hartmann opened this issue 7 years ago • 3 comments

How much work would it be to add a function to merge deltas?

This will benefit all use cases where a JSON model changes more frequently than the daltas are shipped for processing, by aggregating all deltas between shipping cycles and sending only the aggregated delta.

Benefit:

  • It eliminates the issue of overflowing delta queues.
  • It reduces bandwidth when shipping deltas over the wire,
  • It reduces processing cycles used for consuming the deltas.

Doable?

peter-hartmann avatar Jan 05 '18 05:01 peter-hartmann

it's not trivial, but surely it's doable, this is a duplicate of #39, a PR or some reference implementation would be welcome.

benjamine avatar Jan 05 '18 12:01 benjamine

What I do is run two stacks at a time, I keep the original in a "clean" state and then a live "working" model. When I "Publish" I push the Working onto the original and save the delta between them.

I have a single "Original to now" delta (Major), and a "since last change" delta array (Minor).

I generate two diff's on changes (actually I have a long debounce on the "Major") so then I have an aggregate of changes since the last "Major" and all the minors.. If that helps at all.

DennisSmolek avatar Feb 19 '18 19:02 DennisSmolek

I started experimenting with a small library to do this: https://github.com/marcello3d/jsondiffpatch-flatten

It seems like it's possible, but I haven't covered all the edge cases to know for sure. I'm also doing a very simplistic merge for Unidiff (concatting the changes) that should be optimized.

marcello3d avatar Jun 07 '21 20:06 marcello3d