Skip to content

perf(mempool): replace proto marshaling with arithmetic in ComputeProtoSizeForTxs#32

Open
JayT106 wants to merge 1 commit intocrypto-org-chain:v0.38.xfrom
JayT106:perf/reap-max-bytes-max-gas
Open

perf(mempool): replace proto marshaling with arithmetic in ComputeProtoSizeForTxs#32
JayT106 wants to merge 1 commit intocrypto-org-chain:v0.38.xfrom
JayT106:perf/reap-max-bytes-max-gas

Conversation

@JayT106
Copy link
Copy Markdown

@JayT106 JayT106 commented Mar 16, 2026

Summary

Backport of cometbft/cometbft#5694.

  • ComputeProtoSizeForTxs previously allocated a Data{} struct and marshaled to protobuf per call, causing O(n) allocations in the hot ReapMaxBytesMaxGas path
  • Replace with direct arithmetic (tag byte + varint length + data) that matches the protobuf wire format exactly
  • Benchmarks show ~2x speedup and allocations drop from 1-per-tx to 1 total across all mempool sizes

ComputeProtoSizeForTxs previously allocated a Data{} struct and
marshaled to protobuf per call, causing O(n) allocations in the hot
ReapMaxBytesMaxGas path. Replace with direct arithmetic (tag byte +
varint length + data) that matches the protobuf wire format exactly.

Benchmarks show ~2x speedup and allocations drop from 1-per-tx to 1
total across all mempool sizes.

Backport of cometbft#5694.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@JayT106 JayT106 self-assigned this Mar 16, 2026
@JayT106 JayT106 requested a review from songgaoye March 16, 2026 14:21
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.

1 participant