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

chore: Parallel clones for large data structures #78

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/provider/pedersen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<G: Group> {
#[abomonate_with(Vec<[u64; 8]>)] // this is a hack; we just assume the size of the element.
ck: Vec<G::PreprocessedGroupElement>,
}

/// [CommitmentKey]s are often large, and this helps with cloning bottlenecks
impl<G: Group> Clone for CommitmentKey<G> {
fn clone(&self) -> Self {
Self {
ck: self.ck.par_iter().cloned().collect(),
}
}
}

impl<G: Group> Len for CommitmentKey<G> {
fn length(&self) -> usize {
self.ck.len()
Expand Down
14 changes: 13 additions & 1 deletion src/r1cs/sparse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use serde::{Deserialize, Serialize};

/// CSR format sparse matrix, We follow the names used by scipy.
/// Detailed explanation here: <https://stackoverflow.com/questions/52299420/scipy-csr-matrix-understand-indptr>
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Abomonation)]
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Abomonation)]
#[abomonation_bounds(where <F as PrimeField>::Repr: Abomonation)]
pub struct SparseMatrix<F: PrimeField> {
#[abomonate_with(Vec<F::Repr>)]
Expand All @@ -26,6 +26,18 @@ pub struct SparseMatrix<F: PrimeField> {
pub cols: usize,
}

/// [SparseMatrix]s are often large, and this helps with cloning bottlenecks
impl<F: PrimeField> Clone for SparseMatrix<F> {
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<F: PrimeField> SparseMatrix<F> {
/// 0x0 empty matrix
pub fn empty() -> Self {
Expand Down
Loading