Skip to content

Commit c798d4a

Browse files
authored
Merge pull request go-git#503 from jfontan/fix/similarity-matrix-too-big
plumbing: object, rename calculation uses too much memory
2 parents acd6c65 + 1115cb6 commit c798d4a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

plumbing/object/rename.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -403,10 +403,16 @@ func min(a, b int) int {
403403
return b
404404
}
405405

406+
const maxMatrixSize = 10000
407+
406408
func buildSimilarityMatrix(srcs, dsts []*Change, renameScore int) (similarityMatrix, error) {
407409
// Allocate for the worst-case scenario where every pair has a score
408410
// that we need to consider. We might not need that many.
409-
matrix := make(similarityMatrix, 0, len(srcs)*len(dsts))
411+
matrixSize := len(srcs) * len(dsts)
412+
if matrixSize > maxMatrixSize {
413+
matrixSize = maxMatrixSize
414+
}
415+
matrix := make(similarityMatrix, 0, matrixSize)
410416
srcSizes := make([]int64, len(srcs))
411417
dstSizes := make([]int64, len(dsts))
412418
dstTooLarge := make(map[int]bool)

0 commit comments

Comments
 (0)