While addition and removal are very fast to detect, "move" detection is rather costly, and running createPatch between two large objects (~17kb each, see .zip attachment) can take several seconds even on my Ryzen 9 5950X. While a patch with singles moves will be smaller than a patch with pairs of remove-and-add, I will happily take a faster createPatch even if it makes applying the patch an order of magnitude slower:
import { readFileSync, writeFileSync } from "node:fs";
import { createPatch, applyPatch } from "rfc6902";
let s, e;
const text1 = readFileSync(`test1.json`);
const obj1 = JSON.parse(text1);
const obj3 = JSON.parse(text1);
const text2 = readFileSync(`test2.json`);
const obj2 = JSON.parse(text2);
s = performance.now();
const patch = createPatch(obj1, obj2);
e = performance.now();
console.log(`patch creation took ${e - s}ms`);
writeFileSync(`patch.json`, JSON.stringify(patch));
s = performance.now();
applyPatch(obj3, patch);
e = performance.now();
console.log(`patching took ${e - s}ms`);
console.log(
`obj1 successfully turned into obj2:`,
createPatch(obj2, obj3).length === 0
);
leads to:
$node test.js
patch creation took 1996.171ms
patching took 2.758600000000115ms
obj1 successfully turned into obj2: true
And even though there are no moves in the resulting patch, I would imagine the code paths necessary to determine whether there are any moves costs cycles?
(if there are other ways to speed up the diffing processing though, I'd be more than happy to take those too)
diff-test.zip
While addition and removal are very fast to detect, "move" detection is rather costly, and running
createPatchbetween two large objects (~17kb each, see .zip attachment) can take several seconds even on my Ryzen 9 5950X. While a patch with singles moves will be smaller than a patch with pairs of remove-and-add, I will happily take a fastercreatePatcheven if it makes applying the patch an order of magnitude slower:leads to:
And even though there are no moves in the resulting patch, I would imagine the code paths necessary to determine whether there are any moves costs cycles?
(if there are other ways to speed up the diffing processing though, I'd be more than happy to take those too)
diff-test.zip