Skip to content

Commit 4a8d5b5

Browse files
authored
CSHARP-5412: Performance: Avoid allocations of BsonDeserializationContext when deserialising a batch (#1540)
1 parent 03432b0 commit 4a8d5b5

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/MongoDB.Driver/Core/Operations/CursorBatchDeserializationHelper.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,13 @@ public static List<TDocument> DeserializeBatch<TDocument>(RawBsonArray batch, IB
4949
using (var stream = new ByteBufferStream(batch.Slice, ownsBuffer: false))
5050
using (var reader = new BsonBinaryReader(stream, readerSettings))
5151
{
52+
var context = BsonDeserializationContext.CreateRoot(reader);
53+
5254
// BSON requires that the top level object be a document, but an array looks close enough to a document that we can pretend it is one
5355
reader.ReadStartDocument();
5456
while (reader.ReadBsonType() != 0)
5557
{
5658
reader.SkipName(); // skip over the index pseudo names
57-
var context = BsonDeserializationContext.CreateRoot(reader);
5859
var document = documentSerializer.Deserialize<TDocument>(context);
5960
documents.Add(document);
6061
}

0 commit comments

Comments
 (0)