onmyway133 / DeepDiff

🦀Amazingly incredible extraordinary lightning fast diffing in Swift
https://onmyway133.com/apps/
Other
2.05k stars 143 forks source link

DeepDiff too slow when comparing 2 string arrays. #38

Closed Gocy015 closed 5 years ago

Gocy015 commented 5 years ago

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?

Gocy015 commented 5 years ago

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..

onmyway133 commented 5 years ago

@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.

Gocy015 commented 5 years ago

ok, thx!