kyuupichan / aiorpcX

Generic async RPC implementation, including JSON-RPC
MIT License
27 stars 23 forks source link

save some bandwidth: strip redundant whitespaces from json encoding #38

Closed SomberNight closed 3 years ago

SomberNight commented 3 years ago

This saves a few bytes of bandwidth at virtually no cost.

>>> import json
>>> o = {"jsonrpc": "2.0", "method": "blockchain.estimatefee", "id": 3, "params": [10]}
>>>
>>> json.dumps(o)
'{"jsonrpc": "2.0", "method": "blockchain.estimatefee", "id": 3, "params": [10]}'
>>> json.dumps(o, separators=(',', ':'))
'{"jsonrpc":"2.0","method":"blockchain.estimatefee","id":3,"params":[10]}'

see https://github.com/python/cpython/blob/f6c6b5821bff815bdc810de53992fd1fbdb2edd4/Lib/json/__init__.py#L148-L151

kyuupichan commented 3 years ago

Are we that tight on bandwidth? It seems some tests need updating too.

SomberNight commented 3 years ago

It seems some tests need updating too.

I've updated some; let's see now.

Are we that tight on bandwidth?

Well, no, of course not; if we were we should not use hex strings. However changing to raw bytes would be much more work. This PR makes an easy and minor backwards compatible change that still saves a few bytes on every request (so probably 1-2% of bandwidth overall).