You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Morten Kloster <mo...@gmail.com> on 2011/05/26 22:42:57 UTC

[PATCH] Simplification/speed-up of libsvn_diff by eliminating idx

[[[
Simpler/faster LCS algorithm in libsvn_diff by elimination of idx.

* subversion/libsvn_diff/lcs.c
  (svn_diff__snake_t): Removed idx parameter (always 0)
  (svn_diff__lcs_t): Removed idx variable (always 0) , let d have either
   sign, and moved the origo of fp by d. New version no longer chooses
   the shorter file as the "original", and can thus give different LCS's
   depending on the order of the input files even when the files have
   different lengths. Speed is ~15% faster for core lcs algorithm.
]]]

The old version of the LCS algorithm started at k=0 and ended at
k=d, where d is the length difference of the two files. d was required
to be positive. It is more efficient to start at k=(-)d and end at 0 (since
ending the loops at 0 allows for faster comparisons), and this also
makes it easy to let d have either sign, which makes the idx variable
unnecessary, further increasing speed by eliminating a parameter
to the frequently called function svn_diff__snake_t. The sign of d
is handled in the initial values of the loops (which have minimal speed
impact).

The new version will more often give different (but equally good) results
depending on the order of the input files. I estimated the speed
difference by diffing all of the first 100 revisions of merge.c in
libsvn_client against each other (when diffing only against the previous
revision, the core LCS algorithm usually takes a minor part of the total
running time, so this is not suitable for gauging the LCS algorithm
speed).


Morten