-
Notifications
You must be signed in to change notification settings - Fork 516
Closed
Description
Hi there, I've been having some performance problems with createPatch
and have managed to create a minimal example that replicates the problem. The patch creation takes about 20,000 times longer than it should. It seems to occur when I'm doing large truncations. Here's the code:
const {performance} = require("perf_hooks");
const JsDiff = require('diff');
const diff_match_patch = require("diff-match-patch");
const dmp = new diff_match_patch();
function makePatch(oldText, newText) {
let t;
t = performance.now();
let textPatch1 = JsDiff.createPatch("foo.txt", oldText+"\n", newText+"\n", "", "");
console.log("JsDiff (ms):", performance.now()-t);
t = performance.now();
let textPatch2 = dmp.patch_make(oldText+"\n", newText+"\n");
console.log("diff_patch_match (ms):", performance.now()-t);
}
// make a string of 25k lines of random numbers:
text1 = new Array(25000).fill(0).map(n => new Array(20).fill(1).map(n => Math.floor(Math.random()*10)).join("")).join("\n");
// grab the first 10,000 characters:
text2 = text1.slice(0, 10000);
// make the patch:
makePatch(text1, text2);
Here's the output I get for that:
JsDiff (ms): 133238.9396559
diff_patch_match (ms): 6.825272083282471
So unless I'm doing something wrong here, there's a huge performance disparity between this package and the diff-patch-match
package for patch creation in certain situations. diff-patch-match
is normally about 2x-10x faster depending on the size of the strings, but here its a lot faster... so something's obviously going wrong here.
This is what I'm seeing in the profiler:
Any idea what's happening here?
ScenK, alexloehr, GeekBerry, lgrammel, hacke2 and 1 more
Metadata
Metadata
Assignees
Labels
No labels