Skip to content

Commit

Permalink
CSHARP-5412: Performance: Avoid allocations of BsonDeserializationCon…
Browse files Browse the repository at this point in the history
…text when deserialising a batch (mongodb#1540)
  • Loading branch information
obligaron authored Nov 20, 2024
1 parent 03432b0 commit 4a8d5b5
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ public static List<TDocument> DeserializeBatch<TDocument>(RawBsonArray batch, IB
using (var stream = new ByteBufferStream(batch.Slice, ownsBuffer: false))
using (var reader = new BsonBinaryReader(stream, readerSettings))
{
var context = BsonDeserializationContext.CreateRoot(reader);

// 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
reader.ReadStartDocument();
while (reader.ReadBsonType() != 0)
{
reader.SkipName(); // skip over the index pseudo names
var context = BsonDeserializationContext.CreateRoot(reader);
var document = documentSerializer.Deserialize<TDocument>(context);
documents.Add(document);
}
Expand Down

0 comments on commit 4a8d5b5

Please sign in to comment.