Details
-
Bug
-
Resolution: Done
-
Major - P3
-
3.0.0
-
None
Description
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;
|
}
|
}
|