Skip to content

Emit compact JSON for outgoing JSON-RPC payloads#3842

Open
genisis0x wants to merge 1 commit into
ApeWorX:mainfrom
genisis0x:perf/3496-compact-json-rpc-encoding
Open

Emit compact JSON for outgoing JSON-RPC payloads#3842
genisis0x wants to merge 1 commit into
ApeWorX:mainfrom
genisis0x:perf/3496-compact-json-rpc-encoding

Conversation

@genisis0x
Copy link
Copy Markdown

Summary

`FriendlyJsonSerde.json_encode` left `json.dumps` at its default separators, which pad every entry with `", "` and `": "`. Every payload web3.py sends is consumed by another machine, so the spacing is pure overhead.

Pass `separators=(",", ":")` to drop ~2 bytes per dict/list entry. This adds up across large payloads (`eth_getLogs` results, batched JSON-RPC requests, verbose websocket logs) without changing semantics.

Closes #3496 (compact-encoding portion of the issue; other suggestions there can be addressed in follow-up PRs).

Test plan

  • Existing `test_friendly_json_encode_with_web3_json_encoder` and `test_encode_rpc_request` already compare via `literal_eval`, so spacing changes do not regress them.
  • Local `python -c` round-trip confirms compact output is still valid JSON-RPC.

FriendlyJsonSerde.json_encode left json.dumps at its default separators,
which pad every entry with ", " and ": ". Every payload that web3.py
sends is consumed by another machine, so the spacing is pure overhead.
Pass `separators=(",", ":")` to drop ~2 bytes per dict/list entry. This
adds up across large payloads such as `eth_getLogs` results, batched
JSON-RPC requests, and verbose websocket logs without changing
semantics.

Closes ApeWorX#3496 (compact-encoding portion)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

make json improvements

1 participant