Skip to content

Commit 7dd9a06

Browse files
committed
Make DRIFT_RANGE dynamic based on height of images
We've added DRIFT_RANGE as a performance boost for the lcs implementation. Instead of checking infinitely long windows of similarities, we've been capping the search at 200px. When images are long however, the 200 range isn't enough. To make large diffs more correct, we're applying the range dynamically based on the height of the image. 10% or 200px, whichever is largest.
1 parent 3e6cb73 commit 7dd9a06

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/alignArrays.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,15 @@ function longestCommonSubsequence(a, b) {
3838
const memo = initMatrix(aLength + 1, bLength + 1);
3939
const solution = initMatrix(aLength + 1, bLength + 1);
4040

41+
const usedDriftRange = Math.abs(
42+
Math.max(Math.max(aLength, bLength) / 10, DRIFT_RANGE),
43+
);
44+
4145
// Loop and find the solution
4246
for (let i = 1; i <= aLength; i += 1) {
4347
for (
44-
let j = Math.max(1, i - (DRIFT_RANGE / 2));
45-
j <= Math.min(bLength, i + (DRIFT_RANGE / 2));
48+
let j = Math.max(1, i - usedDriftRange / 2);
49+
j <= Math.min(bLength, i + usedDriftRange / 2);
4650
j += 1
4751
) {
4852
if (a[i - 1] === b[j - 1]) {

0 commit comments

Comments
 (0)