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

Regression in LazyBSONObject.entrySet() performance in the 3.x driver

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.4.0
    • Affects Version/s: 3.0.0
    • Component/s: BSON, Performance
    • None

      There is a regression in the performance of LazyBSONObject.entrySet() in the 3.x driver vs. the 2.x driver.

      The below runs in ~80ms with the 2.14 driver and ~8000ms with the 3.3 driver.

      package misc;
      
      import com.mongodb.*;
      
      import java.util.*;
      import java.util.Map.Entry;
      
      import org.bson.*;
      
      public class LazyBsonWalk {
      
          public static void main(String args[]) throws Exception {
              MongoClient mongo = new MongoClient();
              DBCollection coll = mongo.getDB("test").getCollection("doc");
              coll.drop();
      
              coll.setDBDecoderFactory(LazyDBDecoder.FACTORY);
      
              coll.insert(generateDoc());
      
              long start = System.currentTimeMillis();
              walkLazyBSONObject((LazyBSONObject)coll.findOne());
              long end = System.currentTimeMillis();
      
              System.out.println(end - start);
          }
      
          public static void walkLazyBSONObject(LazyBSONObject lazyObj) {
              Set<Entry<String, Object>> set = lazyObj.entrySet();
      
              for(Entry<String, Object> entry : set) {
      
                  Object value = null;
                  value = entry.getValue();
      
                  if (value instanceof LazyBSONObject) {
                      walkLazyBSONObject((LazyBSONObject)value);
                  }
              }
          }
      
          public static DBObject generateDoc() {
              DBObject obj = new BasicDBObject();
      
              for (int i = 0; i < 10; i++) {
                  DBObject obji = new BasicDBObject();
      
                  for (int j = 0; j < 10; j++ ) {
                      DBObject objj = new BasicDBObject();
      
                      for (int k = 0; k < 100; k++) {
                          DBObject data = new BasicDBObject();
                          data.put("clicks", 0);
                          data.put("impressions", 1);
                          data.put("revenue", 100);
      
                          objj.put(String.valueOf(k), data);
                      }
                      obji.put(String.valueOf(j), objj);
                  }
                  obj.put(String.valueOf(i), obji);
              }
      
              return obj;
          }
      }
      

            Assignee:
            jeff.yemin@mongodb.com Jeffrey Yemin
            Reporter:
            steve.briskin Steve Briskin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: