-
Type: Improvement
-
Resolution: Fixed
-
Priority: Unknown
-
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:
- call type(obj) and lookup the type in the encoding table, if the type is not found continue to step 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
- 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.
- is duplicated by
-
PYTHON-4145 bson._MARKERS is missing Decimal128 and DatetimeMS
- Closed
- related to
-
PYTHON-1374 Optimize json_util performance
- Closed
-
PYTHON-4143 Optimize JSON encoding of int, float, str, and None
- Closed