Skip to content

Some optimizations in constraint synthesis.#407

Merged
alireza-shirzad merged 15 commits intomasterfrom
finalize-experiments
Jul 2, 2025
Merged

Some optimizations in constraint synthesis.#407
alireza-shirzad merged 15 commits intomasterfrom
finalize-experiments

Conversation

@Pratyush
Copy link
Copy Markdown
Member

@Pratyush Pratyush commented Jun 26, 2025

Description

  • Switch around PartialOrd and Ord impls to avoid wrapping and then unwrapping Some.
  • Pack Variable into u64 instead of current enum which requires 128 bits due to alignment.
  • Create a new LcMap struct to abstract storage of LinearCombinations.
    • The new LcMap uses a more-cache-friendly storage backend.
  • Introduces a new FieldInterner that avoids duplication of field elements in LinearCombinations in the ConstraintSystem.

Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (master)
  • Linked to Github issue with discussion and accepted design OR have an explanation in the PR that describes this work.
  • Wrote unit tests
  • Updated relevant documentation in the code
  • Added a relevant changelog entry to the Pending section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer

@Pratyush Pratyush marked this pull request as ready for review June 27, 2025 03:49
@Pratyush Pratyush requested a review from Copilot June 27, 2025 05:02
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces several optimizations in constraint synthesis, including a refactor of the variable representation (packing into a u64), improved management of linear combinations via a new LcMap structure, and the introduction of a FieldInterner to avoid duplicated field elements. Key changes include:

  • Refactoring the implementation of variables with more efficient inline and const functions.
  • Creating a new LcMap for more cache-friendly storage of linear combinations and adding parallel iterator support.
  • Enhancing documentation and consistency across modules, as well as cleaning up minor style issues.

Reviewed Changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated no comments.

Show a summary per file
File Description
relations/src/utils/variable.rs Refactored variable representation with new constructors and inlined functions.
relations/src/utils/matrix.rs Annotated the transpose function with a must_use attribute.
relations/src/utils/linear_combination.rs Updated LC creation, compactification and introduced IntoIterator for LCs.
relations/src/gr1cs/lc_map.rs Introduced LcMap with parallel iterator support and detailed unsafe block documentation.
relations/src/gr1cs/constraint_system.rs Integrated FieldInterner and LcMap into constraint system construction and updated LC handling.
Other gr1cs, predicate, and test files Updated documentation references, refined naming conventions, and fixed style issues (e.g., semicolons, saturating_sub usage).
Comments suppressed due to low confidence (2)

relations/src/gr1cs/constraint_system.rs:479

  • [nitpick] The helper function new_lc_add_helper now returns a Variable directly rather than a Result. Confirm that all callers are updated accordingly and that error conditions are correctly handled upstream.
    ) -> Variable {

relations/src/gr1cs/lc_map.rs:216

  • Ensure that all invariants used to justify the unsafe block in windowed_access are formally verified (e.g., via unit tests or static assertions) to maintain the safety guarantees of the function.
) -> LcMapIterItem<'a> {

@Pratyush Pratyush requested review from alireza-shirzad and removed request for alireza-shirzad July 1, 2025 09:26
@alireza-shirzad alireza-shirzad merged commit 4c740f7 into master Jul 2, 2025
4 checks passed
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.

3 participants