Skip to content

rust: use bytes::Bytes for proto fields #4677

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

Merged
merged 1 commit into from
Feb 16, 2021
Merged

Conversation

wchargin
Copy link
Contributor

Summary:
This patch changes our proto bindings for bytes fields from Vec<u8>
to Bytes. The advantage is that they can be shared and sliced
cheaply. For example, the ReadBlob RPC no longer needs to clone the
full contents of the blob to refer to it after dropping the read lock,
and it also no longer needs to clone each sent chunk.

Correspondingly, we now represent blob sequences as Vec<Bytes> (seems
pretty sensible). Another option is Vec<Arc<[u8]>> here, but creating
an Arc<[u8]> from a Vec<u8> or Bytes requires a full copy.

This patch is made mostly by updating gen_protos_tool and pushing
through the type changes.

Test Plan:
For most of these changes, type-checking is sufficient; for the changes
to ReadBlob, unit tests are relevant, too.

wchargin-branch: rust-bytes

Summary:
This patch changes our proto bindings for `bytes` fields from `Vec<u8>`
to [`Bytes`]. The advantage is that they can be shared and sliced
cheaply. For example, the `ReadBlob` RPC no longer needs to clone the
full contents of the blob to refer to it after dropping the read lock,
and it also no longer needs to clone each sent chunk.

Correspondingly, we now represent blob sequences as `Vec<Bytes>` (seems
pretty sensible). Another option is `Vec<Arc<[u8]>>` here, but creating
an `Arc<[u8]>` from a `Vec<u8>` or `Bytes` [requires a full copy].

This patch is made mostly by updating `gen_protos_tool` and pushing
through the type changes.

[`Bytes`]: https://docs.rs/bytes/1.0.1/bytes/struct.Bytes.html
[requires a full copy]: https://stackoverflow.com/a/44641572

Test Plan:
For most of these changes, type-checking is sufficient; for the changes
to `ReadBlob`, unit tests are relevant, too.

wchargin-branch: rust-bytes
wchargin-source: 59248986d03702cb3e7dd66e8e69f4dcdf6a059f
@wchargin wchargin added theme:performance Performance, scalability, large data sizes, slowness, etc. core:rustboard //tensorboard/data/server/... labels Feb 11, 2021
@google-cla google-cla bot added the cla: yes label Feb 11, 2021
@wchargin wchargin requested a review from psybuzz February 11, 2021 04:01
@wchargin
Copy link
Contributor Author

An alternate description of this change would be “avoid 2n bytes worth
of copies in ReadBlob, and plumb bytes::Bytes through as necessary”.
Most of the mass of this patch is just pushing types through, but the
actual payoffs are the Bytes::clone and slice_ref(...) in server.

@wchargin
Copy link
Contributor Author

@psybuzz: Friendly ping?

Copy link
Contributor

@psybuzz psybuzz left a comment

Choose a reason for hiding this comment

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

Sorry for the long delay, lgtm!

@wchargin
Copy link
Contributor Author

No problem; thanks!

@wchargin wchargin merged commit 4790603 into master Feb 16, 2021
@wchargin wchargin deleted the wchargin-rust-bytes branch February 16, 2021 23:19
wchargin added a commit that referenced this pull request Feb 25, 2021
Summary:
Nothing critical: some unnecessary `.into()`s from #4677 and some
unnecessary `&Box<T>` double-indirection from #4689.

wchargin-branch: rust-clippy-fixes-20210225
wchargin-source: 27bd0fee8a91ed809d78b07bbcaf60dd0c276fef
wchargin added a commit that referenced this pull request Feb 26, 2021
Summary:
Nothing critical: some unnecessary `.into()`s from #4677 and some
unnecessary `&Box<T>` double-indirection from #4689.

wchargin-branch: rust-clippy-fixes-20210225
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes core:rustboard //tensorboard/data/server/... theme:performance Performance, scalability, large data sizes, slowness, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants