Performance: Avoid allocations of BsonDeserializationContext when deserialising a batch

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Fixed
    • Priority: Unknown
    • 3.1.0
    • Affects Version/s: 3.0.0
    • None
    • None
    • Fully Compatible
    • Dotnet Drivers
    • Not Needed
    • None
    • None
    • None
    • None
    • None
    • None

      When deserialising a result batch, a BsonDeserializationContext is created for each document/object.

      The logic can be changed to reuse the BsonDeserializationContext instance for each document/object.

      The same reuse already happens in the driver in  CommandMessageBinaryEncoder.ReadType1Section.

      This reduces allocations and GC load.

      Current implementation:

      Method BenchmarkDataSetSize Mean Error StdDev Gen0 Gen1 Gen2 Allocated
      MultiFileExport 565000000 8.230 s 0.7249 s 0.1882 s 516000.0000 304000.0000 3000.0000 7.73 GB

      Reuse implementation:

      Method BenchmarkDataSetSize Mean Error StdDev Gen0 Gen1 Gen2 Allocated
      MultiFileExport 565000000 8.191 s 0.2030 s 0.0314 s 514000.0000 318000.0000 3000.0000 7.68 GB

       

              Assignee:
              Ferdinando Papale
              Reporter:
              obligaron N/A
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: