google-code-export / morphia

Automatically exported from code.google.com/p/morphia
1 stars 0 forks source link

Suggestion for performance improvement of QueryImpl.fetch #373

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What version are you using? (Morphia/Driver/MongoDB): 0.99-1/2.7.2/2.0

In QueryImpl.prepareCursor, this line:

        cursor.setDecoderFactory( this.ds.getDecoderFact() );

could generate a lot more garbage than necessary, based on implementation 
details of 2.7.x driver series.

We'll generate less garbage to only set decoder factory on the cursor if it's 
different than 

  this.ds.getMongo().getMongoOptions().dbDecoderFactory

Doing that will allow the driver to use a cached decoder (cached in DBPort)

Original issue reported on code.google.com by jeff.ye...@gmail.com on 2 Feb 2012 at 1:37

GoogleCodeExporter commented 9 years ago
This is not possible since the scope of the decoder is just for the query, not 
the Mongo instance as you suggest.

Original comment by scotthernandez on 2 Feb 2012 at 1:41

GoogleCodeExporter commented 9 years ago
Won't this work:

 if (this.ds.getDecoderFact() != this.ds.getMongo().getMongoOptions().dbDecoderFactory) {
    cursor.setDecoderFactory( this.ds.getDecoderFact() );
}

Original comment by jeff.ye...@gmail.com on 2 Feb 2012 at 2:56

GoogleCodeExporter commented 9 years ago
Yep... we could even do that in the driver :) ... on the set method.

Original comment by scotthernandez on 2 Feb 2012 at 3:08

GoogleCodeExporter commented 9 years ago
Definitely, it can and should be fixed in the driver, but may not be in the 
2.7.x line.

Original comment by jeff.ye...@gmail.com on 2 Feb 2012 at 3:18

GoogleCodeExporter commented 9 years ago
FYI, DatastoreImpl.java:

public DBDecoderFactory getDecoderFact() { return decoderFactory != null ? 
decoderFactory : mongo.getMongoOptions().dbDecoderFactory; }

And at some point this may be exposed in Morphia but for now it is just there 
because I was testing the lazy decoding in some tests and needed to be able to 
change it for a few Datastore instances in the test where I din't want to use 
the default set. In practice nobody sets a custom decoder via morphia except in 
those tests.

Original comment by scotthernandez on 2 Feb 2012 at 5:27