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
    • 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.

        1. image-2019-02-06-13-41-14-545.png
          57 kB
          dnickless
        2. image-2019-02-06-14-13-47-136.png
          51 kB
          dnickless

            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: