-
Notifications
You must be signed in to change notification settings - Fork 577
Optimize Msm #796
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
Optimize Msm #796
Conversation
str4d
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 27fddaf. Thanks!
d897fd4 to
7de8af3
Compare
str4d
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 7de8af3
halo2_proofs/src/arithmetic.rs
Outdated
| let mut acc = C::Curve::identity(); | ||
| let mut sum = C::Curve::identity(); | ||
| buckets.iter().rev().for_each(|b| { | ||
| sum = b.add(sum); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That doesn't work, because sum has type C::Curve, not Bucket, and we can't impl<C: Curve> AddAssign<Bucket<C::AffineRepr>> for C because it would be a foreign impl.
EDIT: I now see you edited your suggestion, and that one works fine.
| } | ||
| Bucket::Projective(a) => other + &a, | ||
| } | ||
| fn add(self, mut other: C::Curve) -> C::Curve { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bucket::add was an existing function that is preserved in this PR, so in the interest of not needing to go through another round of CI, I'm going to defer this internal rename.
nuttycom
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK 7de8af3
| type Item; | ||
|
|
||
| /// Combines the best of `std::iter` and `rayon` reductions. | ||
| fn the_best_reduce( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙃 at the name, but this is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I needed something that was not likely to clash in future with a std or rayon name 😄
Msm Optimization
Hi there.
I optimized the best_multiexp algorithm and replaced it with a more efficient rayon method.
What I did
Task Size
Before
Current implementation divides task into coeffs length / thread number parts.
The greater the parallelism used by
rayon(by default given by the number of logical cores as determined by std::thread::available_parallelism), the smaller the task size of each thread process.It causes task size to be too heavy for small-core PCs and too small for large-core PCs.
After
Flatten task size to addition and sum of bucket for each segment.
Parallelization Scope
Before
The current implementation performs final sum with a non-parallel process.
After
Include the final sum to parallel scope.
Rayon Method
Before
According to official documentation, speed relation is as follows: join ≤ par_iter ≤ scope
After
Replace
best_multiexpscope withpar_iterOther
Refactoring
Bucketandget_at.Benchmark
I ran best_multiexp benchmark twice
after -> beforeandbefore -> afterin order to make machine condition same.First
Second
I would appreciate it if you could confirm.
Thank you.