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

Improve performance of ObjectId hex string parsing

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 4.9.0
    • Affects Version/s: None
    • Component/s: BSON
    • Labels:
      None
    • Fully Compatible
    • Not Needed

      The built-in ObjectId parseHexString() implementation is somewhat slow, because it calls Integer.parseInt() 12 times. Replacing with hand-coded hex parsing achieves something like a 5x improvement.

      Performance test (ran on master and on branch on my M1 Mac):

          public static void main(String[] args) {
              long startTime = System.currentTimeMillis();
              for (int i = 10000000; i < 100000000; i++)

      {             new ObjectId("1234567890abcdef" + i);         }

              long endTime = System.currentTimeMillis();

              System.out.println("Time elapsed: " + (endTime - startTime));
          }

      On master:

      Time elapsed: 19460

      On branch:

      Time elapsed:  3617

            Assignee:
            jeff.yemin@mongodb.com Jeffrey Yemin
            Reporter:
            ian@charthop.com Ian White
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: