From a4d0a80466016281c3f2b90a1ade66338d258153 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Thu, 25 May 2023 08:43:52 +0300 Subject: refactor(tvix/store/bin): instantiating TvixStoreIO once Instead of instantiating it once in every loop iteration, put it in an Arc, and clone that before passing it to the spawned task. Change-Id: I5d9c838f27048726166fa50206d1edd5ed6849b5 Reviewed-on: https://cl.tvl.fyi/c/depot/+/8632 Autosubmit: flokli Tested-by: BuildkiteCI Reviewed-by: tazjin --- tvix/store/src/bin/tvix-store.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/tvix/store/src/bin/tvix-store.rs b/tvix/store/src/bin/tvix-store.rs index feda586fcb46..5912c6464bfe 100644 --- a/tvix/store/src/bin/tvix-store.rs +++ b/tvix/store/src/bin/tvix-store.rs @@ -2,6 +2,7 @@ use clap::Subcommand; use data_encoding::BASE64; use std::io; use std::path::PathBuf; +use std::sync::Arc; use tracing_subscriber::prelude::*; use tvix_store::blobservice::SledBlobService; use tvix_store::directoryservice::SledDirectoryService; @@ -129,18 +130,19 @@ async fn main() -> Result<(), Box> { directory_service.clone(), ); + let io = Arc::new(TvixStoreIO::new( + blob_service, + directory_service, + path_info_service, + nar_calculation_service, + )); + for path in paths { let path_move = path.clone(); - - let mut io = TvixStoreIO::new( - blob_service.clone(), - directory_service.clone(), - path_info_service.clone(), - nar_calculation_service.clone(), - ); - + let io_move = io.clone(); let path_info = tokio::task::spawn_blocking(move || { - io.import_path_with_pathinfo(&path_move) + io_move + .import_path_with_pathinfo(&path_move) .map_err(|e| io::Error::new(io::ErrorKind::Other, e.to_string())) }) .await??; -- cgit 1.4.1