CSHARP-1378 BulkWrite enumerates requests argument multiple times #314
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
BulkWrite
currently enumerates itsrequests
param 3 times:requests
into the result objectThat behaviour can be very costly if
requests
represents e.g. a remote db table.This pull requests contains 2 commits:
CSHARP-1378 enumerate bulkwrite request list once: Simply copies the enumerable to a list once and uses that list everywhere the enumerable was used. Includes a unit test that fails for the case where
BulkWrite
/BulkWriteAsync
enumerates the enumerable multiple times.CSHARP-1378 remove extra list copy: With the above commit
BulkWrite
does one more list copy than in the baseline case. This second commit optimizes that extra copy away because I don't want to worsen performance for cases whererequests
is cheap to enumerate. I put it in a separate commit because you might find avoiding the extra list copy not worth the hassle because "computers are fast now".Some tests fail in my ad-hoc environment, but then they also fail there without these changes, so that should be ok.