Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-2504

Reduce memory consumption because of lambda closures in BsonWriter.WriteName

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 2.12.0
    • Affects Version/s: 2.7.3
    • Component/s: Performance, Serialization
    • Labels:
      None

      The profiler output of a session that involved serialization of more than 2 million complex documents shows the following result - 36GB of memory allocated only by the BsonWriter.WriteName method:

      The culprit for that appears to be the lambda expression here: https://github.com/mongodb/mongo-csharp-driver/blob/dc2dbb5ff06fdea80b44a8c2295e542f166ccb16/src/MongoDB.Bson/IO/BsonWriter.cs#L279

      _childElementNameValidatorFactory = () => _elementNameValidator.GetValidatorForChildContent(name);

      It would certainly be beneficial to move to an alternative design that does not result in closures.

            Assignee:
            boris.dogadov@mongodb.com Boris Dogadov
            Reporter:
            daniel.hegener@gmx.net Daniel Hegener
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: