Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-4179

Optimize JSON decoding performance by avoiding object_pairs_hook

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 4.7
    • Affects Version/s: None
    • Component/s: JSON, Performance

      ilukyanchikov has created PR #1493: PYTHON-1374: Optimized performance by removing object_pairs_hook call if we need the default conversion to dict behavior in mongo-python-driver

      Issue Text:
      Optimized performance by removing object_pairs_hook call if we need the default conversion to dict behavior [jira task](https://jira.mongodb.org/projects/PYTHON/issues/PYTHON-1374)
      In object_hook, a dictionary is already passed, and calling object_pairs_hook for casting pairs to dict is redundant.
      I validated my changes with test_json_util cases. `pytest -v -s test/test_json_util.py`
      Compare performance with TestJson*Decoding cases(changes affect performance only in these cases) `pytest -v -s test/performance/perf_test.py::TestJsonFlatDecoding test/performance/perf_test.py::TestJsonDeepDecoding test/performance/perf_test.py::TestJsonFullDecoding`

      Test Name master current branch
      ------------------ ------------------ --------------------
      JsonFlatDecoding 96.18636555725531 117.50816018425552
      JsonDeepDecoding 58.337081713027956 77.52136671585596
      JsonFullDecoding 33.81260536995342 38.88821810950474

      This fix only works with JSONOptions where document_class is dict, and I haven't found cases where something other than dict was used.

            Assignee:
            shane.harvey@mongodb.com Shane Harvey
            Reporter:
            dbeng-pm-bot PM Bot
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: