Skip to content

CSHARP-1378 BulkWrite enumerates requests argument multiple times #314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

M-frankied
Copy link

BulkWrite currently enumerates its requests param 3 times:

  • to check whether it is empty
  • to build the bulkwrite operation
  • to copy requests into the result object

That 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 where requests 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.

@jyemin jyemin added the crud label Nov 18, 2020
@sanych-sun sanych-sun requested review from sanych-sun and removed request for MikalaiMazurenka March 8, 2024 00:12
@sanych-sun
Copy link
Member

Thank you for your contribution. This PR was very helpful and excellent starting point for me to fix the original issue in another PR #1298.

@sanych-sun sanych-sun closed this Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants