Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion web3/_utils/encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,13 @@ def _friendly_json_encode(
self, obj: dict[Any, Any], cls: type[json.JSONEncoder] | None = None
) -> str:
try:
encoded = json.dumps(obj, cls=cls)
# Use the most compact separators. The JSON-RPC spec is
# whitespace-agnostic, every RPC request/response we serialize is
# consumed by another machine, and the default ", "/": " padding
# adds ~2 bytes per dict/list entry across very large payloads
# (e.g. eth_getLogs, batched calls). Saves bandwidth and log
# volume without changing semantics.
encoded = json.dumps(obj, cls=cls, separators=(",", ":"))
return encoded
except TypeError as full_exception:
if hasattr(obj, "items"):
Expand Down
Loading