DeepDiff too slow when comparing 2 string arrays.
Gocy015 opened this issue · 3 comments
Hi,
i am trying to implement a text-base diff viewer, my code looks like the following:
let originalLines = originalSource.split(separator: "\n", omittingEmptySubsequences: false).map{String($0)}
let diffLines = diffSource.split(separator: "\n", omittingEmptySubsequences: false).map{String($0)}
let algorithmStart = CACurrentMediaTime()
let diffchecker = WagnerFischer<String>(reduceMove: false)
let changes = diffchecker.diff(old: originalLines, new: diffLines)
DC_LOG_INFO("DiffVC, diff algorithm cost \(CACurrentMediaTime() - algorithmStart)")
my sample files are 2 objc source files with 650+lines, and only 1 line is different , and the log prints out:
DiffVC, diff algorithm cost 6.890240641998389
Any idea of why this is so slow?
I've notice that if i change the code to
let changes =diff(old: originalLines, new: diffLines)
it becomes much faster, diff
uses Heckel
to diff the arrays, but i want to eliminate Move
, how can i achieve that using Heckel
?
btw, it seems that Heckel
uses delete + insert
instead of replace
, which is another feature that i want..
@Gocy015 Hi, we need to tweak the algorithm code a bit to achieve what you want, but the design of the library is to have move changes. Hope you understand.
ok, thx!