[JAVA-2107] Stop using DBObject.keySet when decoding Created: 04/Feb/16  Updated: 16/Feb/16  Resolved: 05/Feb/16

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

Type: Improvement Priority: Major - P3
Reporter: Roger Kapsi Assignee: Jeffrey Yemin
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File Screenshot_2016-02-04_16-12-10.png    

 Description   

DBObject#keySet is inefficient for instances of BasicBSONList. But currently decoding into DBObject relies on the keySet method to determine if a DBObject should be replaced with a DBRef. This reliance is unnecessary in the case of a BasicBSONList and should be removed.

In general, there is little reason for an application to enumerate the keys of a BSON array.

Original Description

Please compare the StringRangeSet implementations in the mongo-java-driver 2.x and 3.x and consider throwing out the 3.x version and replace it with 2.x.



 Comments   
Comment by Jeffrey Yemin [ 16/Feb/16 ]

Closed for 3.2.2 release

Comment by Jeffrey Yemin [ 05/Feb/16 ]

Roger,

Instead of changing StringRangeSet, I fixed the performance issue you are seeing by short-circuiting the call to keySet() in DefaultDBCallback.objectDone when the type is a BasicBSONList.

Comment by Githook User [ 05/Feb/16 ]

Author:

{u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}

Message: JAVA-2107: Optimize DefaultDBCallback.objectDone by only looking to see if the BSONObject should be replaced by a DBRef if it's not an instance of BasicBSONList
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/e2752c41f1a1e91cfc79cb95c62b73e1d44081fe

Comment by Githook User [ 05/Feb/16 ]

Author:

{u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}

Message: JAVA-2107: Optimize DefaultDBCallback.objectDone by only looking to see if the BSONObject should be replaced by a DBRef if it's not an instance of BasicBSONList
Branch: 3.2.x
https://github.com/mongodb/mongo-java-driver/commit/dadb5d9837aedebcecf657f63c35695184b6c48d

Comment by Jeffrey Yemin [ 04/Feb/16 ]

Perfect, thanks. We'll take a closer look and get this fixed one way or the other.

Comment by Roger Kapsi [ 04/Feb/16 ]

I don't have any specifics other than running YourKit (with CPU tracing) in our production environment and StringRangeSet showed up. It appears to be called from DBCursor (I'm including a screenshot of the call tree). We don't have any direct use-cases of that class.

Comment by Jeffrey Yemin [ 04/Feb/16 ]

Thanks for point this out, Roger. I'm curious though what your use case is that you're even encountering this. StringRangSet is only used internally by org.bson.types.BasicBSONList#keySet, and it would be unusual to require the keys from a BSON array, since they should be entirely predictable based on the size of the list.

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