starknet_committer: buffer streamed compress/decompress for state commitment infos - #14887
starknet_committer: buffer streamed compress/decompress for state commitment infos#14887gkaempfer wants to merge 2 commits into
Conversation
…nfos Feed bincode serialization straight into the zstd encoder (and zstd-decoded bytes straight into bincode deserialization) instead of buffering the full uncompressed payload in an intermediate Vec first. This runs once per block on the committer<->batcher critical path, where the payload can be large enough that the caller needed compression to fit an RPC response cap. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Wrap the zstd encoder/decoder with BufWriter/BufReader so bincode's per-field small writes/reads are coalesced before crossing into zstd's FFI layer, instead of triggering one zstd call per field. This keeps the peak-memory win from streaming while also being faster than the original buffered implementation (measured ~24% faster compress, ~5% faster decompress on realistic payloads), and produces byte-identical output. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
PR SummaryLow Risk Overview Docs on both methods explain why buffering is required. Wire format and compression level are unchanged, so existing stored frames should still round-trip. Reviewed by Cursor Bugbot for commit dedd21c. Bugbot is set up for automated code reviews on this repo. Configure here. |
Summary
Automated performance follow-up, scoped to the
CompressedStateCommitmentInfoscodec introduced in #14884 (which reachedmainaround the same time as the branch-sync #14883 that triggered this review).StateCommitmentInfos::compress()/CompressedStateCommitmentInfos::decompress()previously buffered the full uncompressed bincode payload in an intermediateVec<u8>before/after feeding it to zstd. This runs once per block on the committer↔batcher critical path, and the payload is exactly the data #14884 needed to compress in the first place because it was large enough to blow past the RPC response cap.This PR streams bincode serialization directly into a zstd encoder (and zstd-decompressed bytes directly into bincode deserialization), wrapped in
BufWriter/BufReaderso bincode's small per-field writes/reads are coalesced before crossing into zstd's FFI layer.Net effect, measured with a tracking allocator on realistic payloads (~18.8 MB uncompressed):
Test plan
cargo test -p starknet_committer --features os_input— 129 passedcargo test -p apollo_committer --features os_input— 14 passed (round-trips throughcompress()/decompress()viaread_paths_and_commit_block_happy_flow,revert_removes_witnesses_and_digest, etc.)cargo test -p apollo_storage --features os_input state_commitment_infos— 2 passedcargo clippy -p starknet_committer --features os_input --all-targets -- -D warnings— cleanscripts/rust_fmt.sh --check— cleanBufWriter/BufReaderwrapping in this PR was added specifically to address that and make it an unambiguous win.Note
This is scoped to the codec itself. The review also surfaced a pre-existing, higher-severity issue outside this diff's scope:
echonet/os_input_builder.pystill doesjson.loads()on what is now a bincode-encoded payload (a consequence of #14884), which will break echonet OS runs — flagging separately rather than fixing here since it's unrelated to this optimization.🤖 Generated with Claude Code
Generated by Claude Code