Skip to content

perf: reserve repeated message decode capacity - #1454

Open
perfloop-agent wants to merge 2 commits into
tokio-rs:masterfrom
perfloop-oss:perfloop-pr-open-9k0k8cb9z6
Open

perfloop-agent wants to merge 2 commits into
tokio-rs:masterfrom
perfloop-oss:perfloop-pr-open-9k0k8cb9z6

Conversation

@perfloop-agent

@perfloop-agent perfloop-agent commented Aug 9, 2026 •

Copy link
Copy Markdown

Summary

  • Carry the generated repeated-message field tag through DecodeContext so message::merge_repeated can reserve capacity for contiguous same-tag fields after decoding the first element.
  • Scan the common canonical one-byte tag/length envelope directly, with the generic varint scanner retained for all other inputs, and inline the generated-call-site helper to keep the decode hot path lean.
  • Preserve the public four-argument merge_repeated API. The narrowly scoped Clippy allowance keeps the existing nested condition compatible with the crate's edition 2021.

Compatibility and limits

Reservation only considers complete fields in the current buffer chunk and enclosing message scope, and remains bounded by the existing lookahead and reservation limits. Fragmented, incomplete, non-contiguous, or hand-written Message decode paths retain the existing fallback behavior. Decoded output is unchanged.

Performance

Workload: repeated-message-decode-64

Metric Before After Change
allocation_calls/op 5 1 80% lower
reallocation_calls/op 4 0 100% lower
requested_allocation_bytes/op 496 256 48.4% lower

Workload: repeated-message-decode-4096

Metric Before After Change
allocation_calls/op 11 3 72.7% lower
reallocation_calls/op 10 2 80% lower
requested_allocation_bytes/op 32752 28672 12.5% lower

Testing

Ran formatting, warning-denied Clippy including Rust 1.95, no-default-features checking, feature-specific test configurations, no-recursion-limit tests, benchmark compilation, and warning-denied rustdoc.

All 8 declared correctness checks passed.


Authored and verified by Perfloop: every claim above was co-measured on both trees and independently re-verified before submission — the full record is public: case_pfmqga57j8. Replies from this account are human-approved, and a human operator is accountable for this contribution.

Carry generated field tags through DecodeContext so repeated message decoding can reserve bounded capacity for contiguous same-tag fields in the current message scope.

Inline the repeated-message merge helper for generated call sites and scan canonical one-byte envelopes directly; the generic scanner remains the fallback for all other inputs.

Keep the nested metadata and capacity conditions stable with a scoped Clippy allowance.
@perfloop-agent
perfloop-agent force-pushed the perfloop-pr-open-9k0k8cb9z6 branch from f76cf0e to 3d0cfc5 Compare August 9, 2026 11:29
@tsenart

tsenart commented Aug 9, 2026

Copy link
Copy Markdown

Related to #1451

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.

2 participants