starknet_committer,apollo_committer: avoid compressing state commitment infos twice per block - #14886
starknet_committer,apollo_committer: avoid compressing state commitment infos twice per block#14886gkaempfer wants to merge 2 commits into
Conversation
…nt infos twice per block PR #14884 introduced CompressedStateCommitmentInfos and, on the CommitTip path, compresses the committed state commitment infos twice per block: once inside write_with_metadata_and_commitment_infos (via a full deep clone of the HashMap-heavy StateCommitmentInfos) for the forest DB write, and again for the RPC response. Compress once and reuse the (much cheaper to clone) compressed bytes for both. On the Historical/replay path, read_commitment_infos decompressed the already-compressed bytes from storage only for the caller to immediately recompress them for the response. Since CompressedStateCommitmentInfos is what's stored and what's needed downstream, return it directly and skip the decompress+recompress round trip entirely. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QdQH5898m3XVzEUPq94aRZ
…ess fix - Keep compress() inside the Action::Write measurement window so write-latency metrics stay comparable to before this change. - Rename the Historical-branch binding to compressed_state_commitment_infos so the same identifier isn't used for both StateCommitmentInfos and CompressedStateCommitmentInfos within read_paths_and_commit_block. - Remove the now-unreachable From<StateCommitmentInfosCodecError> for SerializationError impl (its only caller was the compress() call removed from IndexDb::write_with_metadata_and_commitment_infos). - Reword comments to state the invariant rather than narrate the diff. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QdQH5898m3XVzEUPq94aRZ
PR SummaryLow Risk Overview On new commits, On historical replay,
Reviewed by Cursor Bugbot for commit 698ff11. Bugbot is set up for automated code reviews on this repo. Configure here. |
Summary
Follow-up performance fix to #14884 ("compress state commitment infos"), which introduced
CompressedStateCommitmentInfosso the committer's OS-input witness data travels compressed across the batcher/orchestrator/storage boundaries instead of as a large JSON-serialized structure.That PR left two redundant-work paths in
Committer::read_paths_and_commit_block(crates/apollo_committer/src/committer.rs):state_commitment_infoswas compressed twice per committed block — once via a full clone fed intowrite_with_metadata_and_commitment_infos(which internally compressed it again to persist to the forest DB), and once more directly for the RPC response. This PR compresses once and reuses the (much cheaper to clone) compressed bytes for both the DB write and the response.read_commitment_infosdecompressed the already-compressed bytes read from storage into a fullStateCommitmentInfos, only for the caller to immediately recompress them for the response — a pure decompress+recompress round trip on data that was never touched in between.ForestReaderWithWitnesses::read_commitment_infosnow returnsCompressedStateCommitmentInfosdirectly (a raw byte passthrough from storage), skipping decompression on this path entirely.Also:
CommitmentInfosWrite.commitment_infoschanged fromStateCommitmentInfostoCompressedStateCommitmentInfos, soIndexDb::write_with_metadata_and_commitment_infosstores the bytes as-is instead of compressing them itself. Removed the now-unreachableFrom<StateCommitmentInfosCodecError> for SerializationErrorimpl whose only caller was the deleted internalcompress()call.An Opus review pass confirmed the change is behavior-preserving (same bytes to DB, same bytes in the response) and flagged one metric-semantics nuance, which is addressed by keeping
compress()inside theAction::Writemeasurement window so write-latency metrics stay comparable to before.Test plan
cargo check -p starknet_committer -p apollo_committer -p apollo_committer_typeswith and without--features os_input,testingcargo test -p starknet_committer -p apollo_committer --features os_input,testing— 129 + 14 tests passcargo clippy -p starknet_committer -p apollo_committer -p apollo_committer_types --features os_input,testing --all-targets -- -D warnings— cleanscripts/rust_fmt.sh --check— no diff🤖 Generated with Claude Code
https://claude.ai/code/session_01QdQH5898m3XVzEUPq94aRZ
Generated by Claude Code