[CSHARP-161] Preallocating a list when reading a large message Created: 27/Jan/11 Updated: 02/Apr/15 Resolved: 27/Jan/11 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | 1.0 |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Aristarkh Zagorodnikov | Assignee: | Robert Stam |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
I suggest to improve MongoReplyMessage<TDocument>.ReadFrom(BsonBuffer) by preallocating a list of documents, since its size is known, and doing it after error checking (so we don't allocate anything if cursor died, etc.). — MongoReplyMessage.cs.orig Thu Jan 27 18:36:48 2011
var settings = new BsonBinaryReaderSettings { MaxDocumentSize = server.MaxDocumentSize }; + documents = new List<TDocument>(numberReturned); |
| Comments |
| Comment by Robert Stam [ 27/Jan/11 ] |
|
Implemented. Set the initial capacity of the documents list to the number of documents returned. |