From a6580748aabe7fcbea735396ac700661b6c53e87 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Thu, 20 Jul 2023 13:37:29 +0300 Subject: feat(tvix/store/digests): use bytes::Bytes instead of Vec This will save us some copies, because a clone will simply create an additional pointer to the same data. Change-Id: I017a5d6b4c85a861b5541ebad2858ad4fbf8e8fa Reviewed-on: https://cl.tvl.fyi/c/depot/+/8978 Reviewed-by: raitobezarius Autosubmit: flokli Tested-by: BuildkiteCI --- tvix/store/src/directoryservice/grpc.rs | 17 +++++++++-------- tvix/store/src/directoryservice/traverse.rs | 6 ++++-- tvix/store/src/directoryservice/utils.rs | 2 +- 3 files changed, 14 insertions(+), 11 deletions(-) (limited to 'tvix/store/src/directoryservice') diff --git a/tvix/store/src/directoryservice/grpc.rs b/tvix/store/src/directoryservice/grpc.rs index b9a5036a9140..e6f34b2bd80c 100644 --- a/tvix/store/src/directoryservice/grpc.rs +++ b/tvix/store/src/directoryservice/grpc.rs @@ -142,12 +142,13 @@ impl DirectoryService for GRPCDirectoryService { .spawn(async move { grpc_client.put(tokio_stream::iter(vec![directory])).await }); match self.tokio_handle.block_on(task)? { - Ok(put_directory_resp) => Ok(B3Digest::from_vec( - put_directory_resp.into_inner().root_digest, - ) - .map_err(|_| { - Error::StorageError("invalid root digest length in response".to_string()) - })?), + Ok(put_directory_resp) => Ok(put_directory_resp + .into_inner() + .root_digest + .try_into() + .map_err(|_| { + Error::StorageError("invalid root digest length in response".to_string()) + })?), Err(e) => Err(crate::Error::StorageError(e.to_string())), } } @@ -265,7 +266,7 @@ impl Iterator for StreamIterator { for child_directory in &directory.directories { // We ran validate() above, so we know these digests must be correct. let child_directory_digest = - B3Digest::from_vec(child_directory.digest.clone()).unwrap(); + child_directory.digest.clone().try_into().unwrap(); self.expected_directory_digests .insert(child_directory_digest); @@ -355,7 +356,7 @@ impl DirectoryPutter for GRPCPutter { .map_err(|e| Error::StorageError(e.to_string()))? .root_digest; - B3Digest::from_vec(root_digest).map_err(|_| { + root_digest.try_into().map_err(|_| { Error::StorageError("invalid root digest length in response".to_string()) }) } diff --git a/tvix/store/src/directoryservice/traverse.rs b/tvix/store/src/directoryservice/traverse.rs index 17f709f40d1d..a6e61a813b16 100644 --- a/tvix/store/src/directoryservice/traverse.rs +++ b/tvix/store/src/directoryservice/traverse.rs @@ -1,5 +1,5 @@ use super::DirectoryService; -use crate::{proto::NamedNode, B3Digest, Error}; +use crate::{proto::NamedNode, Error}; use std::{os::unix::ffi::OsStrExt, sync::Arc}; use tracing::{instrument, warn}; @@ -40,7 +40,9 @@ pub fn traverse_to( Ok(None) } crate::proto::node::Node::Directory(directory_node) => { - let digest = B3Digest::from_vec(directory_node.digest) + let digest = directory_node + .digest + .try_into() .map_err(|_e| Error::StorageError("invalid digest length".to_string()))?; // fetch the linked node from the directory_service diff --git a/tvix/store/src/directoryservice/utils.rs b/tvix/store/src/directoryservice/utils.rs index d152fb78a90c..95f02f1f9ce8 100644 --- a/tvix/store/src/directoryservice/utils.rs +++ b/tvix/store/src/directoryservice/utils.rs @@ -35,7 +35,7 @@ impl DirectoryTraverser { fn enqueue_child_directories(&mut self, directory: &proto::Directory) { for child_directory_node in &directory.directories { // TODO: propagate error - let child_digest = B3Digest::from_vec(child_directory_node.digest.clone()).unwrap(); + let child_digest: B3Digest = child_directory_node.digest.clone().try_into().unwrap(); if self.worklist_directory_digests.contains(&child_digest) || self.sent_directory_digests.contains(&child_digest) -- cgit 1.4.1