Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-153

BSONEncoder putObject optimization for Map

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Trivial - P5 Trivial - P5
    • 2.2
    • Affects Version/s: 2.1
    • Component/s: None
    • Labels:
      None

      In BSONEncoder.putObject(), the core field put loop is:
      for ( String s : o.keySet() ) {
      // ...
      _putObjectField(s, o.get(s));
      }

      For Map-based implementations of DBObject/BSONObject (the defaults), this is a fast operation. However, if the underlying data isn't directly stored in a Map (but in a List or some other non-random-access data structure), this is relatively inefficient.

      There are two potential solutions to this:
      1) Pull the Map and iterate over the entrySet() of the underlying Map
      2) Add a Set<Entry> entrySet() method to BSONObject

      #1 is the solution which doesn't involve backwards incompatibility (as it doesn't involve adding a new method on BSONObject which would have to be implemented by all subclasses), but #2 would be the cleanest in comparison with the existing code.

            Assignee:
            scotthernandez Scott Hernandez (Inactive)
            Reporter:
            kirk Kirk Wylie
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: