Skip to content

Commit

Permalink
Merge pull request #503 from jfontan/fix/similarity-matrix-too-big
Browse files Browse the repository at this point in the history
plumbing: object, rename calculation uses too much memory
  • Loading branch information
mcuadros committed Nov 17, 2022
2 parents acd6c65 + 1115cb6 commit c798d4a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion plumbing/object/rename.go
Expand Up @@ -403,10 +403,16 @@ func min(a, b int) int {
return b
}

const maxMatrixSize = 10000

func buildSimilarityMatrix(srcs, dsts []*Change, renameScore int) (similarityMatrix, error) {
// Allocate for the worst-case scenario where every pair has a score
// that we need to consider. We might not need that many.
matrix := make(similarityMatrix, 0, len(srcs)*len(dsts))
matrixSize := len(srcs) * len(dsts)
if matrixSize > maxMatrixSize {
matrixSize = maxMatrixSize
}
matrix := make(similarityMatrix, 0, matrixSize)
srcSizes := make([]int64, len(srcs))
dstSizes := make([]int64, len(dsts))
dstTooLarge := make(map[int]bool)
Expand Down

0 comments on commit c798d4a

Please sign in to comment.