Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-4195

Investigate NODE-4194 - Performance regression of parsing ObjectId type fields

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
    • Not Needed

      NODE-4194 Description
      In our Node.js app, after updating MongoDB Node.js driver from v3.6.10 to v4.3.1 we noticed up to 50% performance regression of endpoints that fetch data from MongoDB (v5.0). Each document in the affected collections have at least one field of ObjectId type. After an investigation it looks like parsing ObjectId type fields now takes significant amount of time in comparison with the previous driver v3.6.10.
      I came up with the load test that you can run to reproduce the regression:

      https://github.com/baryshok/mongodb-object-id-driver-v3

      https://github.com/baryshok/mongodb-object-id-driver-v4

      It populates `test` collection with 50k docs of shape `

      { _id: ObjectId, field1: "value1" }

      ` and fetches all those documents 100 times concurrently.

      With driver v3.6 this test takes ~10 secs on my local env, with v4.3 – ~15 secs:

      If I switch to using `string` type instead of `ObjectId` for `_id` field: `

      { _id: string, field1: "value1" }

      ` the test results for driver v4.3 become almost equal to the ones for v3.6

      The CPU profile for v4.3 shows that ObjectId -> ensureBuffer takes ~3 seconds out of 15 seconds that the whole test takes

      I wonder if there's a way to bring back the performance of v3.6 to v4.3 in terms of parsing ObjectId type fields. Thank you!

        1. driver-3610-fetch-50k-docs-100-times.cpuprofile
          1.35 MB
        2. driver-431-fetch-50k-docs-100-times.cpuprofile
          1.46 MB
        3. driver-431-fetch-50k-docs-100-times-string-id.cpuprofile
          1.42 MB
        4. image-2022-04-20-17-06-03-986.png
          image-2022-04-20-17-06-03-986.png
          102 kB
        5. image-2022-04-20-17-06-40-610.png
          image-2022-04-20-17-06-40-610.png
          13 kB
        6. image-2022-04-20-17-06-57-554.png
          image-2022-04-20-17-06-57-554.png
          13 kB
        7. image-2022-04-20-17-07-13-221.png
          image-2022-04-20-17-07-13-221.png
          13 kB
        8. image-2022-04-20-17-07-47-209.png
          image-2022-04-20-17-07-47-209.png
          14 kB
        9. image-2022-04-20-17-08-22-548.png
          image-2022-04-20-17-08-22-548.png
          13 kB
        10. image-2022-04-20-17-25-47-182.png
          image-2022-04-20-17-25-47-182.png
          13 kB

            Assignee:
            neal.beeken@mongodb.com Neal Beeken
            Reporter:
            dbeng-pm-bot PM Bot
            Votes:
            5 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: