Perf: Improve compiler speed - #427
Open
anudit wants to merge 1 commit into
Open
Conversation
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.
While testing our circuits we found some performance improvements.
This speeds up compilation ~2x across the board.
Changes
execute_componentdeep-cloned the wholeComponentRepresentation(hashmap of memory slices, each cloningAssignmentState+ ASTMeta) on every signal access into a subcomponent. Nowaccess_values_by_reference- read-only there anyway, same bounds checks and errors. This clone is what the 2.1.9→2.2.x component/bus rework introduced.constraint_generation/src/execute.rswrite_constraint_usizeandapply_correspondenceare now generic over the hasher.circom_algebra/src/fast_hash.rs(new);circom_algebra,constraint_list,dagcircom/src/main.rsmodulus(a,b)computed((a % b) + b) % b; sincea % bis already in(-b, b)for positiveb, the second division was always a no-op.circom_algebra/src/modular_arithmetic.rslto = "thin",codegen-units = 1,panic = "abort"- the workspace had no[profile.release]at all.Cargo.tomlBug fixes
Two
circom_algebratests already failed on unmodifieda100fae;complementdidn't reduce its operand. It truncates to the field's bit width before flipping, so an operand>= fieldlost its high bits and~~x != x mod p. Now reduces into[0, field)first, like every other op in the module.algebra_constraint_apply_substitutionskipped a step.apply_substitutiondeliberately leaves the raw form (explicit constant coefficients, zero or not); its internalfix_constraintis commented out because the pipeline calls it afterwards. The test now does the same.Benchmarks on some of our circuits
Apple M2 Max (12 cores, 64 GB, macOS arm64). hyperfine with warmup, heavy circuits
×3 runs, light ×10. Flags:
--r1cs --wasm --c -l ./node_modules. All three binariesmeasured identically.
keccak256jwt1024oauth512jwt512jwt256aadhaarrsasha256semaphore20loginProofmerkle