Skip to content

Commit

Permalink
Performance: use fewer operations in generate sum loop (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
JayWhite2357 authored Apr 19, 2023
1 parent 026fb83 commit 6b88896
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

### Improvements

- [\#71](https://github.com/arkworks-rs/sumcheck/pull/71) Improve prover performance by using an arithmetic sequence rather than interpolation inside of the `prove_round` loop.

- [\#55](https://github.com/arkworks-rs/sumcheck/pull/55) Improve the interpolation performance and avoid unnecessary state clones.

### Bug fixes
Expand Down
24 changes: 14 additions & 10 deletions src/ml_sumcheck/protocol/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,25 @@ impl<F: Field> IPForMLSumcheck<F> {

let mut products_sum = Vec::with_capacity(degree + 1);
products_sum.resize(degree + 1, F::zero());
let mut product = Vec::with_capacity(degree + 1);
product.resize(degree + 1, F::zero());

// generate sum
for b in 0..1 << (nv - i) {
let mut t_as_field = F::zero();
for old_product in products_sum.iter_mut().take(degree + 1) {
for (coefficient, products) in &prover_state.list_of_products {
let mut product = *coefficient;
for &jth_product in products {
let table = &prover_state.flattened_ml_extensions[jth_product];
product *= table[b << 1] * (F::one() - t_as_field)
+ table[(b << 1) + 1] * t_as_field;
for (coefficient, products) in &prover_state.list_of_products {
product.fill(*coefficient);
for &jth_product in products {
let table = &prover_state.flattened_ml_extensions[jth_product];
let mut start = table[b << 1];
let step = table[(b << 1) + 1] - start;
for p in product.iter_mut() {
*p *= start;
start += step;
}
*old_product += product;
}
t_as_field += F::one();
for t in 0..degree + 1 {
products_sum[t] += product[t];
}
}
}

Expand Down

0 comments on commit 6b88896

Please sign in to comment.