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

Optimize json_util encoding performance using single dispatch table

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

      Split from PYTHON-1374.


      Currently, the JSON encoder performs a chain of isinstance checks sprinkled in with a "_type_marker" lookup. We can optimize this further by using a single dispatch table similar to how the pure python BSON encoder works:

      1. call type(obj) and lookup the type in the encoding table, if the type is not found continue to step 2:
      2. access obj._type_marker, if it exists and is one of our known types, add type(obj) to the encoding table and encode it, otherwise continue to step 3
      3. perform the chain of isinstance checks, if it's a subclass of the known type, add type(obj) to the encoding table and encode it, otherwise raise TypeError.

      Definition of done

      Make the above refactor and measure the performance to ensure there are no regressions and perf has improved.

            shane.harvey@mongodb.com Shane Harvey
            shane.harvey@mongodb.com Shane Harvey
            0 Vote for this issue
            1 Start watching this issue