-
Type: Improvement
-
Resolution: Done
-
Priority: Minor - P4
-
Affects Version/s: None
-
Component/s: None
-
None
-
Fully Compatible
While profiling one of our applications, I encountered that BsonArray implementation was relatively suboptimal when it's initialized with a medium-large sized (100-1000 elements) arrays. So, I created a patch which supports reserving space in internal values array if the amount of elements is known beforehand (if IEnumerable<T> is also an ICollection), along with some iteration improvements for arrays and IList<T> implementations. In my test case this leads to around 40-50% improvement on array creation. I also applied the same improvements to relevant methods (Clone, DeepClone). While I recognized that attached patch is largely untested, I ask you to consider if these improvements are worth including, and either include the changes I propose, or invent some other scheme to improve the T[]->BsonArray conversion process.