Some optimizations in constraint synthesis.#407
Merged
alireza-shirzad merged 15 commits intomasterfrom Jul 2, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
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> {
alireza-shirzad
approved these changes
Jul 2, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
PartialOrdandOrdimpls to avoid wrapping and then unwrappingSome.Variableintou64instead of currentenumwhich requires128bits due to alignment.LcMapstruct to abstract storage ofLinearCombinations.LcMapuses a more-cache-friendly storage backend.FieldInternerthat avoids duplication of field elements inLinearCombinations in theConstraintSystem.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.
Pendingsection inCHANGELOG.mdFiles changedin the Github PR explorer