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

Closed
wants to merge 10 commits into 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.

@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

Peak Memory Sample

Program Peak Memory %
keccak256 78.48M 0%
workspace 123.78M 0%
regression_4709 422.91M 0%
ram_blowup_regression 1.58G 0%
rollup-base-public 11.27G 10%
rollup-base-private 9.01G 50%
private-kernel-tail 201.81M 0%
private-kernel-reset 739.74M 3%
private-kernel-inner 291.88M 0%
parity-root 172.14M 0%

Copy link
Contributor

github-actions bot commented Dec 14, 2024

Compilation Report

Program Compilation Time %
sha256_regression 1.100s -9%
regression_4709 0.794s -7%
ram_blowup_regression 15.140s -2%
rollup-root 3.760s 0%
rollup-block-merge 4.020s 14%
rollup-base-public 52.100s 66%
rollup-base-private 22.200s 88%
private-kernel-tail 0.975s -6%
private-kernel-reset 14.260s 64%
private-kernel-inner 1.956s -8%

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
Copy link
Contributor

github-actions bot commented Dec 19, 2024

Execution Report

Program Execution Time %
sha256_regression 0.054s 0%
regression_4709 0.001s 0%
ram_blowup_regression 0.574s -1%
rollup-root 0.107s 1%
rollup-block-merge 0.107s 1%
rollup-base-public 1.610s 21%
rollup-base-private 0.613s 19%
private-kernel-tail 0.022s 0%
private-kernel-reset 0.484s 26%
private-kernel-inner 0.097s 0%

Copy link
Contributor

github-actions bot commented Jan 3, 2025

Compilation Memory Report

Program Peak Memory %
keccak256 78.55M 0%
workspace 123.79M 0%
regression_4709 422.96M 0%
ram_blowup_regression 1.58G 0%
rollup-base-public 2.50G 0%
rollup-base-private 1.12G 0%
private-kernel-tail 200.40M 0%
private-kernel-reset 750.85M 3%
private-kernel-inner 290.46M 0%

Copy link
Contributor

github-actions bot commented Jan 3, 2025

Execution Memory Report

Program Peak Memory %
keccak256 74.65M 0%
workspace 123.91M 0%
regression_4709 315.98M 0%
ram_blowup_regression 512.41M 0%
rollup-base-public 796.43M 61%
rollup-base-private 344.13M 3%
private-kernel-tail 181.08M 0%
private-kernel-reset 302.62M 18%
private-kernel-inner 212.78M 0%

Copy link
Contributor

github-actions bot commented Jan 4, 2025

Changes to circuit sizes

Generated at commit: e0d9016217b2b5f0bdf757d499f244754ad0a2d4, compared to commit: 8d7f1f909c50887bca6ff1243d70622c2a3b3ec8

🧾 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 50,846 (+149) +0.29% 114,992 (+161) +0.14%
u128 500 (+4) +0.81% 4,458 (+5) +0.11%
binary_operator_overloading 125 (+2) +1.63% 4,265 (+2) +0.05%
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%
nested_array_dynamic 3,358 (0) 0.00% 12,755 (+1) +0.01%
references 7 (-1) -12.50% 23 (0) 0.00%
slices 758 (+2) +0.26% 3,901 (-5) -0.13%
slice_dynamic_index 995 (-7) -0.70% 6,385 (-20) -0.31%
regression_5252 32,898 (-18) -0.05% 44,243 (-276) -0.62%

@TomAFrench TomAFrench closed this Jan 9, 2025
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