Fix list append complexity issue

This commit is contained in:
Victor Denisov 2016-11-25 22:33:58 -08:00
parent eeb0c7981d
commit 569d8ccc08

View file

@ -807,9 +807,13 @@ mergeUpdateResults
(failed1 || failed2) (failed1 || failed2)
(nMatched1 + nMatched2) (nMatched1 + nMatched2)
((liftM2 (+)) nModified1 nModified2) ((liftM2 (+)) nModified1 nModified2)
(upserted1 ++ upserted2) -- This function is used in foldl1' function. The first argument is the accumulator.
(writeErrors1 ++ writeErrors2) -- TODO this should be rewritten with IO containers. Otherwise its N^2 complexity. -- The list in the accumulator is usually longer than the subsequent value which goes in the second argument.
(writeConcernErrors1 ++ writeConcernErrors2) -- So, changing the order of list concatenation allows us to keep linear complexity of the
-- whole list accumulation process.
(upserted2 ++ upserted1)
(writeErrors2 ++ writeErrors1)
(writeConcernErrors2 ++ writeConcernErrors1)
) )