kpdecker / jsdiff

A javascript text differencing implementation.
BSD 3-Clause "New" or "Revised" License
7.92k stars 496 forks source link

Add timeout? #398

Closed hyrious closed 7 months ago

hyrious commented 1 year ago

Can we add an option like diff_match_path.Diff_Timeout in sync mode? Since #396 may not be solved easily, this option can help reducing many issues about performance like #376

quark-zju commented 1 year ago

FWIW, diff_match_path.Diff_Timeout does not seem to actually work in its Javascript version. Whatever value it is set, the dmp diff algorithm takes the same time. And if the timeout is too small, the diff output is suboptimal (the computation for the more optimal diff is done but dropped due to the timeout logic). So in practice you always want to set it to a large value to avoid discarding the optimal diff output.

ExplodingCabbage commented 7 months ago

Not directly relevant to jsdiff, but for the record, I see different behaviour with diff_match_patch to what you describe, @quark-zju. I tried diffing two random million-line strings against each other with differing Diff_Timeout values and the Diff_Timeout clearly had an effect; when set to 1, execution finished after about 1 second, when set to 10, after about 10 seconds.