Skip to content

Commit

Permalink
plumbing: object, rename calculation uses too much memory
Browse files Browse the repository at this point in the history
The size of the similarity matrix is not limited and can be quite big
when lots of files are deleted and added in a commit.

Signed-off-by: Javi Fontan <jfontan@gmail.com>
(cherry picked from commit 1115cb6)
  • Loading branch information
jfontan authored and weafscast committed Mar 22, 2023
1 parent db61985 commit 9e80177
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 9e80177

Please sign in to comment.