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.

      Context

      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.

            Assignee:
            shane.harvey@mongodb.com Shane Harvey
            Reporter:
            shane.harvey@mongodb.com Shane Harvey
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: