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

Reduce memory consumption because of lambda closures in BsonWriter.WriteName

    XMLWordPrintable

Details

    • Improvement
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • 2.7.3
    • 2.12.0
    • Performance, Serialization
    • None

    Description

      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.

      Attachments

        Issue Links

          Activity

            People

              boris.dogadov@mongodb.com Boris Dogadov
              dnickless dnickless
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: