-
Type: Improvement
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: 2.5.3
-
Component/s: Performance
-
Environment:N/A
When inserting a list of documents via DBCollection.insert( List<DBObject> list ), this List gets converted into an Array:
public WriteResult insert(List<DBObject> list) throws MongoException
{ return insert( list.toArray( new DBObject[list.size()] ) , getWriteConcern() ); }Later on, when it gets to the real implementation of the insert in DBApiLayer.MyCollection.insert, each element of this array is inserted into BSONEncoder ( via OutMessage ). Further this array is never used.
So, it seems that there is no real benefit to convert the initial List into an Array. And for a performance sake, it should be left alone as a List.
For example, in my tests, for a 1,000,000 documents 665 bytes each, "list.toArray( new DBObject[list.size()] )" takes 40 milliseconds. While it may not seem like a lot, it all can add up given a bigger document size / more documents / etc.. And, unless I missed something, there is no good reason for this conversion in the first place.
/Anatoly