Jesse
10/30/2025, 6:36 PMMarvin
10/30/2025, 6:36 PMNate
10/30/2025, 6:37 PMMarvin
10/30/2025, 6:37 PMdef estimate_param_size_bytes(params, prefer_orjson=True):
try:
if prefer_orjson:
import orjson
return len(orjson.dumps(params))
except Exception:
pass
import json
# compact separators minimize size; ensure_ascii=False keeps UTF-8 efficient
payload = json.dumps(params, separators=(",", ":"), ensure_ascii=False).encode("utf-8")
return len(payload)
def estimate_param_size_kb(params):
return estimate_param_size_bytes(params) / 1024
# Example
params = {
"small_flag": True,
"names": ["alice", "bob"],
# ... your params ...
}
size_kb = estimate_param_size_kb(params)
print(f"Estimated serialized size: {size_kb:.2f} KiB")
Tips to stay under 512 KiB:
- Pass references, not data: upload large payloads (dataframes, long lists, models) to object storage (S3/GCS/Azure) and pass a URI or key instead.
- Avoid base64 unless you also compress: base64 adds ~33% overhead. If you must embed data, compress first (e.g., zlib) and then base64.
- Remove whitespace and redundant fields; prefer compact strings and IDs over verbose structures.
- Keep a margin (e.g., target < 450 KiB) to account for small overhead around the parameters in the request.
If you can share:
- Where the 512 KiB limit is coming from in your setup (e.g., Cloud vs. self-hosted, worker type like Docker/Kubernetes/ECS)
- An example structure of your parameters
…I can tailor more specific guidance (and suggest storage/block patterns that fit your worker/platform).Jesse
10/30/2025, 6:41 PMJesse
10/30/2025, 6:43 PM