Skip to content

starknet_committer,apollo_committer: avoid compressing state commitment infos twice per block - #14886

Open
gkaempfer wants to merge 2 commits into
mainfrom
claude/perf/starknet-committer-double-compress-91427
Open

starknet_committer,apollo_committer: avoid compressing state commitment infos twice per block#14886
gkaempfer wants to merge 2 commits into
mainfrom
claude/perf/starknet-committer-double-compress-91427

Conversation

@gkaempfer

Copy link
Copy Markdown
Contributor

Summary

Follow-up performance fix to #14884 ("compress state commitment infos"), which introduced CompressedStateCommitmentInfos so 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):

  • CommitTip branch (new block commits): state_commitment_infos was compressed twice per committed block — once via a full clone fed into write_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.
  • Historical/replay branch: read_commitment_infos decompressed the already-compressed bytes read from storage into a full StateCommitmentInfos, 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_infos now returns CompressedStateCommitmentInfos directly (a raw byte passthrough from storage), skipping decompression on this path entirely.

Also: CommitmentInfosWrite.commitment_infos changed from StateCommitmentInfos to CompressedStateCommitmentInfos, so IndexDb::write_with_metadata_and_commitment_infos stores the bytes as-is instead of compressing them itself. Removed the now-unreachable From<StateCommitmentInfosCodecError> for SerializationError impl whose only caller was the deleted internal compress() 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 the Action::Write measurement window so write-latency metrics stay comparable to before.

Test plan

  • cargo check -p starknet_committer -p apollo_committer -p apollo_committer_types with and without --features os_input,testing
  • cargo test -p starknet_committer -p apollo_committer --features os_input,testing — 129 + 14 tests pass
  • cargo clippy -p starknet_committer -p apollo_committer -p apollo_committer_types --features os_input,testing --all-targets -- -D warnings — clean
  • scripts/rust_fmt.sh --check — no diff

🤖 Generated with Claude Code

https://claude.ai/code/session_01QdQH5898m3XVzEUPq94aRZ


Generated by Claude Code

claude added 2 commits July 27, 2026 12:16
…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
@cursor

cursor Bot commented Jul 27, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Performance-only refactor on witness serialization paths; same bytes to storage and responses, with tests updated for compressed types.

Overview
Eliminates redundant compress/decompress work on OS-input witness payloads in read_paths_and_commit_block.

On new commits, state_commitment_infos is compressed once and the same CompressedStateCommitmentInfos is used for the forest DB write and the RPC response (instead of compressing on write and again for the response, and instead of cloning uncompressed data for persistence).

On historical replay, read_commitment_infos now returns compressed bytes as stored, so the path no longer decompresses from DB only to recompress for the response.

CommitmentInfosWrite and IndexDb persistence take pre-compressed bytes (commitment_infos.0) with no second compression in the DB layer. Tests assert against compressed payloads where appropriate. Removed unused From<StateCommitmentInfosCodecError> for SerializationError.

Reviewed by Cursor Bugbot for commit 698ff11. Bugbot is set up for automated code reviews on this repo. Configure here.

@reviewable-StarkWare

Copy link
Copy Markdown

This change is Reviewable

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.

4 participants