Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-342

On INSERT a List of documents should NOT be converted to a raw Array

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.10.0
    • 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

            Assignee:
            jeff.yemin@mongodb.com Jeffrey Yemin
            Reporter:
            tolitius Anatoly Polinsky
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: