<#1046 [Feature]: Faster JSON dumps in `format_mes...
# meltano-repo-activity
g
#1046 [Feature]: Faster JSON dumps in
format_message
with an alternative JSON SerDe library
Issue created by s7clarke10 ### Feature scope Taps (catalog, state, stream maps, etc.) ### Description Speed of writing messages can add up when you are dumping a large amount of data. One of the things in the original pipelinewise-singer-python was the use of orjson for doing json dumps as it is a lot faster. The particular line in particular is this. sdk/singer_sdk/_singerlib/messages.py Line 165 in</meltano/sdk/commit/796ccda470529253b5211b70742c814d2b20ec07|796ccda> | return json.dumps(message.to_dict(), use_decimal=True, default=str) | | ------------------------------------------------------------------- | We have a variant of pipelinewise-singer-python which uses orjson in favour of json.dumps for improved speed. The code for that section is as follows. import orjson import decimal ... def format_message(message, option=0): def default(obj): if isinstance(obj, decimal.Decimal): return str(obj) raise TypeError return orjson.dumps(message.asdict(), option=option, default=default) Sorry the formatting is all out, I couldn't work out how to get the code formatting working. Best look at the example below. https://github.com/mjsqu/pipelinewise-singer-python/blob/2a839d245b92d1ec6d5801a30f5280fa77b22d0c/singer/messages.py#L295 I note that while orjson is faster it is not perfect, for example we need to convert decimal data as a string. There are some other considerations mentioned with the module but if they are not an issue, we have measured a considerable performance gain using this and verified this by the cProfile to look at the time consumed. meltano/sdk