td-ameritrade-python-api
td-ameritrade-python-api copied to clipboard
JSON Serialization Performance Improvement
Potentially replace response.json() with response.ujson() for serailizing the requets into a dictionary?
https://github.com/areed1192/td-ameritrade-python-api/blob/ab9352aa563e12e34f1a9524f3fd11c51975e065/td/client.py#L654
Interesting, I guess what is the big difference between json()
and usjon()
? I've never header of ujson()
so it's more out of curiosity. 😄
The primary difference is ultra JSON (ujson) is written in C and has Python bindings which makes the encoding/decoding of JSON much faster. I've been testing it on my end with noticeable increases in speed, particularly for the SPY ETF option chain which has arguabaly the most contracts (9000+ contracts each with several key:values)
Your API works so well I figured this is something that could only improve it. I could probably post some of my performacne time tags, but the below two articles, I think, will shed a much greater light on the performance increase. The good thing is that ujson is also a drop in replacement for JSON (unlike some of the other encode/decode formats covered in the articles).
https://medium.com/dataweave/json-vs-simplejson-vs-ujson-2887b2c128b2 https://medium.com/@shmulikamar/python-serialization-benchmarks-8e5bb700530b