Skip to content

feat(view): reserve capacity for packed repeated fields (#171)#172

Closed
yanmo42 wants to merge 1 commit into
anthropics:mainfrom
yanmo42:fix/packed-view-reserve-171
Closed

feat(view): reserve capacity for packed repeated fields (#171)#172
yanmo42 wants to merge 1 commit into
anthropics:mainfrom
yanmo42:fix/packed-view-reserve-171

Conversation

@yanmo42
Copy link
Copy Markdown

@yanmo42 yanmo42 commented Jun 5, 2026

This PR implements capacity reservation for packed repeated scalar view fields as suggested in #171.

Performance

Using the reproduction provided in #171, this change reduces decoding time by approximately 30.4% (7.94s -> 5.53s) on my environment by eliminating redundant reallocations during view creation.

Implementation

  • Added RepeatedView::reserve to the public (but hidden) view API.
  • Updated codegen to emit .reserve() calls before decoding packed fields.
  • Fixed-size types (fixed32, fixed64, float, double) reserve the exact required capacity.
  • Varint types reserve capacity equal to the byte length of the payload (a safe upper bound).

Validation

  • Unit tests for RepeatedView::reserve passed.
  • Codegen test test_view_packed_scalar_reserves_capacity passed.
  • All core buffa and buffa-codegen unit tests passed.
  • Clippy and fmt passed for buffa and buffa-codegen.

Optimize packed repeated scalar view decoding by reserving capacity based on the payload length. This reduces reallocations and provides a ~30% performance boost in microbenchmarks.
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 5, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@yanmo42
Copy link
Copy Markdown
Author

yanmo42 commented Jun 5, 2026

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Jun 5, 2026
@yanmo42
Copy link
Copy Markdown
Author

yanmo42 commented Jun 5, 2026

submitted prematurely, will re-evaluate

@yanmo42 yanmo42 closed this Jun 5, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 5, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant