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

feat: use more efficient field merger code #6815

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

TomAFrench
Copy link
Member

Description

Problem*

Resolves

Summary*

This PR replaces the value merger code reverted in #6673 but solely for fields.

Additional Context

Documentation*

Check one:

  • No documentation needed.
  • Documentation included in this PR.
  • [For Experimental Features] Documentation to be submitted in a separate PR.

PR Checklist*

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt on default settings.

Copy link
Contributor

github-actions bot commented Dec 14, 2024

Changes to number of Brillig opcodes executed

Generated at commit: 8a24fb71e038693d6fd262b93c20a80d8069c363, compared to commit: ddb46733fcf596b5c8508a208b2690df52aa16e3

🧾 Summary (10% most significant diffs)

Program Brillig opcodes (+/-) %
poseidonsponge_x5_254 +3 ❌ +0.00%

Full diff report 👇
Program Brillig opcodes (+/-) %
poseidonsponge_x5_254 183,753 (+3) +0.00%

@TomAFrench TomAFrench added the run-external-checks Trigger CI job to run tests on external repos label Dec 14, 2024
Copy link
Contributor

github-actions bot commented Dec 14, 2024

Changes to circuit sizes

Generated at commit: 8a24fb71e038693d6fd262b93c20a80d8069c363, compared to commit: ddb46733fcf596b5c8508a208b2690df52aa16e3

🧾 Summary (10% most significant diffs)

Program ACIR opcodes (+/-) % Circuit size (+/-) %
array_sort +2 ❌ +3.77% +4 ❌ +3.13%
regression_5252 -18 ✅ -0.05% -276 ✅ -0.62%

Full diff report 👇
Program ACIR opcodes (+/-) % Circuit size (+/-) %
array_sort 55 (+2) +3.77% 132 (+4) +3.13%
hashmap 49,398 (+149) +0.30% 113,174 (+161) +0.14%
u128 641 (+4) +0.63% 4,635 (+5) +0.11%
binary_operator_overloading 284 (+2) +0.71% 4,465 (+2) +0.04%
regression_capacity_tracker 117 (+1) +0.86% 3,972 (+1) +0.03%
bench_eddsa_poseidon 16,441 (+2) +0.01% 19,588 (+2) +0.01%
references 7 (-1) -12.50% 23 (0) 0.00%
slices 771 (+1) +0.13% 3,893 (-5) -0.13%
slice_dynamic_index 1,061 (-14) -1.30% 6,473 (-32) -0.49%
regression_5252 32,898 (-18) -0.05% 44,246 (-276) -0.62%

Copy link
Contributor

github-actions bot commented Dec 14, 2024

Peak Memory Sample

Program Peak Memory %
keccak256 78.15M 0%
workspace 122.74M 0%
regression_4709 423.26M 0%
ram_blowup_regression 1.60G 0%
private-kernel-tail 206.67M 0%
private-kernel-reset 779.58M 4%
private-kernel-inner 312.95M 0%
parity-root 171.68M 0%

Copy link
Contributor

github-actions bot commented Dec 14, 2024

Compilation Sample

Program Compilation Time %
sha256_regression 0m1.358s -1%
regression_4709 0m0.811s 1%
ram_blowup_regression 0m15.003s 1%
rollup-base-public 4m32.746s 14%
rollup-base-private 3m49.925s 23%
private-kernel-tail 0m1.523s 30%
private-kernel-reset 0m14.063s 73%
private-kernel-inner 0m2.303s -6%
parity-root 0m0.961s -1%
noir-contracts 2m57.403s 11%

dfg.insert_instruction_and_results(merged_field, block, None, call_stack.clone())
.first()
} else {
let cast = Instruction::Cast(else_condition, else_type);
Copy link
Contributor

Choose a reason for hiding this comment

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

Related to this I found that when we were casting to Field we saved a lot of range constraints implied on the binary operations performed on Unsigned types. First I thought that must be unsafe as it would mask a potential overflow, but with the c*a + !c*b formula below it seems safe (or actually it has an else_condition below, but assuming that they are mutually exclusive).

I assume you're not doing the c * (a-b) + b trick because of a potential overflow, but isn't it true that mathematically this should be okay, if the cost of the extra Casts to Field would be acceptable?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, we're not concerned about overflows here as the merged value is constrained to then_value or else_value and any underflow in the difference term will disappear (This is why we needed to cast to Fields as the integer types imply checked arithmetic)

I did this just for fields in this PR as this doesn't need the inputs to be casted to fields and back (as it's already the correct type).

@TomAFrench
Copy link
Member Author

I think we should wait for #6817 before pushing this further due to negligible changes within the test suite.

@TomAFrench TomAFrench marked this pull request as draft December 16, 2024 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
run-external-checks Trigger CI job to run tests on external repos
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants