Details
-
Task
-
Resolution: Done
-
Major - P3
-
None
-
None
-
None
-
None
Description
Inserting a LazyDBObject with a large array (20000 ints) is extremely slow...on the order of 500x slower.
Profiling shows the vast majority of the time is spent in the org.bson.io.BSONByteBuffer.getCString() call.
@Test
|
public void testLazyDocWithBigList() {
|
DBCollection c = _db.getCollection("testLazyDotKeysPass");
|
c.drop();
|
|
|
DBObject obj = new BasicDBObject();
|
ArrayList<Integer> arr = new ArrayList<Integer>();
|
for(int i = 0; i < 20000; i++){
|
arr.add(i);
|
}
|
|
obj.put("largeArray", arr);
|
obj.put("randomstr", "asdfasdfa");
|
|
long start = System.currentTimeMillis();
|
c.insert(obj);
|
System.out.println("Save obj: " + (System.currentTimeMillis() - start));
|
|
//convert to a lazydbobject
|
DefaultDBEncoder encoder = new DefaultDBEncoder();
|
byte[] encodedBytes = encoder.encode(obj);
|
|
|
LazyDBDecoder lazyDecoder = new LazyDBDecoder();
|
DBObject lazyObj = lazyDecoder.decode(encodedBytes, c);
|
|
|
start = System.currentTimeMillis();
|
c.insert(lazyObj);
|
System.out.println("Save lazy obj: " + (System.currentTimeMillis() - start));
|
|
//convert lazy to a regular dbobject and save
|
start = System.currentTimeMillis();
|
LazyDBEncoder lazyEncoder = new LazyDBEncoder();
|
BasicOutputBuffer outputBuffer = new BasicOutputBuffer();
|
lazyEncoder.writeObject(outputBuffer, lazyObj);
|
|
DefaultDBDecoder defDecode = new DefaultDBDecoder();
|
DBObject normalObject = defDecode.decode(outputBuffer.toByteArray(), c);
|
|
c.insert(normalObject);
|
System.out.println("Lazy to Basic and save " + (System.currentTimeMillis() - start));
|
}
|
Output
Save obj: 72
|
Save lazy obj: 35194
|
Lazy to Basic and save 131
|