Skip to content

Conversation

@copybara-service
Copy link

Optimize parsing packed repeated fields:

  • If counting varints revealed that each varint takes one byte, skip varint
    parsing. Idea by sbenza@.

  • Do not check if all varints necessarily fit under the current capacity,
    which was done to skip counting varints. Counting varints is now useful
    also to check if each varint takes one byte, and it is now cheap enough
    to perform unconditionally.

    There were actually two capacity checks by mistake, and in the case of
    enough capacity we were doing a slower loop with Add instead of a faster
    loop with setting an element.

  • For bool, check if each byte in the array is a valid representation for
    a bool, i.e. 0 or 1. If so, skip varint parsing and bool normalization.

* If counting varints revealed that each varint takes one byte, skip varint
  parsing. Idea by sbenza@.

* Do not check if all varints necessarily fit under the current capacity,
  which was done to skip counting varints. Counting varints is now useful
  also to check if each varint takes one byte, and it is now cheap enough
  to perform unconditionally.

  There were actually two capacity checks by mistake, and in the case of
  enough capacity we were doing a slower loop with Add instead of a faster
  loop with setting an element.

* For bool, check if each byte in the array is a valid representation for
  a bool, i.e. 0 or 1. If so, skip varint parsing and bool normalization.

PiperOrigin-RevId: 848498407
@github-actions
Copy link

Auto-closing Copybara pull request

@github-actions github-actions bot closed this Dec 31, 2025
@github-actions github-actions bot deleted the test_848498407 branch December 31, 2025 10:07
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