diff --git a/src/provider/pedersen.rs b/src/provider/pedersen.rs index b6bd7d20e..b9e5dfa74 100644 --- a/src/provider/pedersen.rs +++ b/src/provider/pedersen.rs @@ -17,13 +17,22 @@ use rayon::prelude::*; use serde::{Deserialize, Serialize}; /// A type that holds commitment generators -#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Abomonation)] +#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Abomonation)] #[abomonation_omit_bounds] pub struct CommitmentKey { #[abomonate_with(Vec<[u64; 8]>)] // this is a hack; we just assume the size of the element. ck: Vec, } +/// [CommitmentKey]s are often large, and this helps with cloning bottlenecks +impl Clone for CommitmentKey { + fn clone(&self) -> Self { + Self { + ck: self.ck.par_iter().cloned().collect(), + } + } +} + impl Len for CommitmentKey { fn length(&self) -> usize { self.ck.len() diff --git a/src/r1cs/sparse.rs b/src/r1cs/sparse.rs index 387d04914..6c22b67ca 100644 --- a/src/r1cs/sparse.rs +++ b/src/r1cs/sparse.rs @@ -12,7 +12,7 @@ use serde::{Deserialize, Serialize}; /// CSR format sparse matrix, We follow the names used by scipy. /// Detailed explanation here: -#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Abomonation)] +#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Abomonation)] #[abomonation_bounds(where ::Repr: Abomonation)] pub struct SparseMatrix { #[abomonate_with(Vec)] @@ -26,6 +26,18 @@ pub struct SparseMatrix { pub cols: usize, } +/// [SparseMatrix]s are often large, and this helps with cloning bottlenecks +impl Clone for SparseMatrix { + fn clone(&self) -> Self { + Self { + data: self.data.par_iter().cloned().collect(), + indices: self.indices.par_iter().cloned().collect(), + indptr: self.indptr.par_iter().cloned().collect(), + cols: self.cols, + } + } +} + impl SparseMatrix { /// 0x0 empty matrix pub fn empty() -> Self {