Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

protoutil: prefer MarshalToSizedBuffer over MarshalTo where possible #105683

Conversation

nvanbenschoten
Copy link
Member

This commit switches a number of callers of protoutil.MarshalTo over to protoutil.MarshalToSizedBuffer. The latter function is more strict in that it requires the the destination buffer to have a length of exactly pb.Size() bytes, as opposed to only requiring it to have a capacity of at least pb.Size() bytes. In return, it avoids a call to pb.Size().

The three performance-sensitive callers that are changes here are:

  • roachpb.Value.SetProto
  • raftlog.EncodeCommand
  • storage.putBuffer.marshalMeta

The commit also adds some testing-only assertions to verify that callers are using the functions correctly.

Epic: None
Release note: None

@nvanbenschoten nvanbenschoten requested review from a team as code owners June 28, 2023 04:05
@nvanbenschoten nvanbenschoten requested review from a team and jbowens June 28, 2023 04:05
@cockroach-teamcity
Copy link
Member

This change is Reviewable

This commit switches a number of callers of `protoutil.MarshalTo` over
to `protoutil.MarshalToSizedBuffer`. The latter function is more strict
in that it requires the the destination buffer to have a length of
exactly `pb.Size()` bytes, as opposed to only requiring it to have a
capacity of at least `pb.Size()` bytes. In return, it avoids a call to
`pb.Size()`.

The three performance-sensitive callers that are changes here are:
- `roachpb.Value.SetProto`
- `raftlog.EncodeCommand`
- `storage.putBuffer.marshalMeta`

The commit also adds some testing-only assertions to verify that callers
are using the functions correctly.

Epic: None
Release note: None
@nvanbenschoten nvanbenschoten force-pushed the nvanbenschoten/moreMarshalToSizedBuffer branch from 51ac5cf to 7e8051c Compare June 28, 2023 04:22
Copy link
Contributor

@erikgrinaker erikgrinaker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks!

@nvanbenschoten
Copy link
Member Author

TFTR!

bors r=erikgrinaker

@craig
Copy link
Contributor

craig bot commented Jun 28, 2023

Build succeeded:

@craig craig bot merged commit 3c54e12 into cockroachdb:master Jun 28, 2023
@nvanbenschoten nvanbenschoten deleted the nvanbenschoten/moreMarshalToSizedBuffer branch July 17, 2023 16:05
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.

3 participants