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

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • 2.10.0
    • 2.5.3
    • Performance
    • N/A

    Description

      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

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: