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

improve: apply tachyon optimizations(1) #342

Merged
merged 7 commits into from
Jun 3, 2024
Merged

Conversation

guorong009
Copy link

@guorong009 guorong009 commented May 29, 2024

Description

Analyze and apply the tachyon optimizations - 1(Lazy IFFT)

Related issues

Changes

  • remove permutation_product_coset from (permutation::)Committed
  • remove (permutation::)Constructed & use Committed directly

@guorong009 guorong009 self-assigned this May 29, 2024
@codecov-commenter
Copy link

codecov-commenter commented May 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.89%. Comparing base (e931d58) to head (4628c24).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #342      +/-   ##
==========================================
- Coverage   81.90%   81.89%   -0.01%     
==========================================
  Files          82       82              
  Lines       17017    17019       +2     
==========================================
  Hits        13937    13937              
- Misses       3080     3082       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

halo2_backend/src/plonk/permutation/prover.rs Show resolved Hide resolved
halo2_backend/src/plonk/vanishing/prover.rs Show resolved Hide resolved
@@ -447,12 +454,13 @@ impl<C: CurveAffine> Evaluator<C> {
// - z_i(X) \prod_j (p(X) + \delta^j \beta X + \gamma)
// )
let mut current_delta = delta_start * beta_term;
for ((set, columns), cosets) in sets
for (((set_idx, _), columns), cosets) in sets
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about iterating over permutation_product_cosets so that we don't need to manually index at each iteration? Something like this:

                        let mut current_delta = delta_start * beta_term;
                        for ((permutation_product_coset, columns), cosets) in permutation_product_cosets
                            .iter()
                            .zip(p.columns.chunks(chunk_len))
                            .zip(pk.permutation.cosets.chunks(chunk_len))
                        {
                            let mut left = permutation_product_coset[r_next];

I think the code looks slightly more clear this way.

Copy link

@davidnevadoc davidnevadoc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job!
Left a comment/question about a couple of permutation related structs that may be now obsolete.

@@ -25,7 +25,6 @@ use halo2_middleware::poly::Rotation;

pub(crate) struct CommittedSet<C: CurveAffine> {
pub(crate) permutation_product_poly: Polynomial<C::Scalar, Coeff>,
pub(crate) permutation_product_coset: Polynomial<C::Scalar, ExtendedLagrangeCoeff>,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After removing this, how is CommittedSet different from ConstructedSet?
This part of the code is quite poorly documented so it's a bit hard to follow the function of each struct...

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function construct() for Committed may be simplified now to a simple clone() (not sure, some types may need to be fixed).
In fact, after this change I think we should re-evaluate the need of Commited and Constructed, as these may be redundant.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree with you.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about this update? 4628c24
I am sure that we don't need Constructed struct any more.
It also removes unnecessary conversion, which needs .clone().

Copy link

@davidnevadoc davidnevadoc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The optimization looks good!
I still don't understand 100% the logic and purpose behind all the structs surrounding the permutation. I'll try to understand and document that part of the code so it is more understandable.

Copy link
Member

@adria0 adria0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some nitpicks, I do not see any wrong here.
I also tried to check with #345 and it's ok.
Thanks for porting it!

halo2_backend/src/plonk/vanishing/prover.rs Show resolved Hide resolved
pub(crate) struct Evaluated<C: CurveAffine> {
constructed: Constructed<C>,
constructed: Committed<C>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
constructed: Committed<C>,
commited: Committed<C>,

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for suggestion!
Here, I believe it is better to use constructed.
One reason is that it is also the constructed in lookup::prover::Evaluated & shuffle::prover::Evaluated.

Copy link
Member

@ed255 ed255 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@guorong009 guorong009 merged commit b4d1c4c into main Jun 3, 2024
18 checks passed
@guorong009 guorong009 deleted the gr@tachyon-optimize-1 branch June 3, 2024 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants