[JAVA-675] Inefficient object handling Created: 24/Oct/12  Updated: 31/Mar/15  Resolved: 12/Jul/13

Status: Closed
Project: Java Driver
Component/s: Performance
Affects Version/s: 2.9.2
Fix Version/s: 3.0.0

Type: Improvement Priority: Trivial - P5
Reporter: Nils Assignee: Jeffrey Yemin
Resolution: Done Votes: 0
Labels: performance
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible

 Description   

I was debugging through the code and noticed this inefficiency. It's probably not the only place.

DBCollection:
private void _checkKeys( DBObject o ) {
for ( String s : o.keySet() ){
validateKey ( s );
Object inner = o.get( s );
if ( inner instanceof DBObject )

{ _checkKeys( (DBObject)inner ); }

else if ( inner instanceof Map )

{ _checkKeys( (Map<String, Object>)inner ); }

}
}
There should be an alternative implementation that takes a Map and iterates the entry set, to avoid expensive lookup for every single key in the structure. Method _checkKeys should then start with an instanceof check and delegate to this method, if possible, which it probably will be for the vast majority of cases.



 Comments   
Comment by Jeffrey Yemin [ 31/Mar/15 ]

Closing all resolved 3.0.0 issues, as 3.0.0 has been tagged and released.

Comment by Jeffrey Yemin [ 12/Jul/13 ]

In 3.0.x, it's being done during the encoding process. See

https://github.com/mongodb/mongo-java-driver/blob/3.0.x/driver-compat/src/main/com/mongodb/codecs/DBObjectCodec.java#L77
https://github.com/mongodb/mongo-java-driver/blob/3.0.x/driver/src/main/org/mongodb/codecs/DocumentCodec.java#L70

Comment by Jeffrey Yemin [ 27/Oct/12 ]

We can't do this in general since DBOBject does not implement Map. Have you seen this show up in profiling? Typically this kind of inefficiency does not, as I/O tends to be the bottleneck.

Comment by Nils [ 24/Oct/12 ]

Or even better, wait to do such checks until binary serialization, if possible.

Generated at Thu Feb 08 08:52:49 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.