feat(SSA): simplify array_get on slice_insert#10295
feat(SSA): simplify array_get on slice_insert#10295
Conversation
There was a problem hiding this comment.
⚠️ Performance Alert ⚠️
Possible performance regression was detected for benchmark 'ACVM Benchmarks'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.
| Benchmark suite | Current: 0022fa7 | Previous: 52b341d | Ratio |
|---|---|---|---|
perfectly_parallel_batch_inversion_opcodes |
2794287 ns/iter (± 1635) |
2259833 ns/iter (± 14138) |
1.24 |
This comment was automatically generated by workflow using github-action-benchmark.
CC: @TomAFrench
Changes to Brillig bytecode sizes
🧾 Summary (10% most significant diffs)
Full diff report 👇
|
Changes to number of Brillig opcodes executed
🧾 Summary (10% most significant diffs)
Full diff report 👇
|
Changes to circuit sizes
🧾 Summary (10% most significant diffs)
Full diff report 👇
|
There was a problem hiding this comment.
⚠️ Performance Alert ⚠️
Possible performance regression was detected for benchmark 'Test Suite Duration'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.
| Benchmark suite | Current: f232806 | Previous: b43153b | Ratio |
|---|---|---|---|
test_report_zkpassport_noir-ecdsa_ |
3 s |
2 s |
1.50 |
This comment was automatically generated by workflow using github-action-benchmark.
CC: @TomAFrench
There was a problem hiding this comment.
⚠️ Performance Alert ⚠️
Possible performance regression was detected for benchmark 'Execution Time'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.
| Benchmark suite | Current: 957da15 | Previous: b43153b | Ratio |
|---|---|---|---|
rollup-block-root-first-empty-tx |
0.004 s |
0.003 s |
1.33 |
This comment was automatically generated by workflow using github-action-benchmark.
CC: @TomAFrench
vezenovm
left a comment
There was a problem hiding this comment.
I do think these optimizations make sense. They are not super invasive so I would be ok with adding them (especially the parameter array change in try_optimize_array_get_from_previous_set).
| if let Some(length) = context.dfg.get_numeric_constant(arguments[0]) { | ||
| // For `slice_insert(length, ...)` we can replace the resulting length with length + 1 | ||
| let length = length + FieldElement::one(); | ||
| let new_slice_length = context.dfg.instruction_results(instruction_id)[0]; | ||
| Some((new_slice_length, length)) | ||
| } else { | ||
| None | ||
| } |
There was a problem hiding this comment.
| if let Some(length) = context.dfg.get_numeric_constant(arguments[0]) { | |
| // For `slice_insert(length, ...)` we can replace the resulting length with length + 1 | |
| let length = length + FieldElement::one(); | |
| let new_slice_length = context.dfg.instruction_results(instruction_id)[0]; | |
| Some((new_slice_length, length)) | |
| } else { | |
| None | |
| } | |
| // For `slice_insert(length, ...)` we can replace the resulting length with length + 1 | |
| context.dfg.get_numeric_constant(arguments[0]).map(|length| { | |
| let length = length + FieldElement::one(); | |
| let new_slice_length = context.dfg.instruction_results(instruction_id)[0]; | |
| (new_slice_length, length) | |
| }) |
nit: option for reducing nesting
| None | ||
| } | ||
| } else if slice_remove.is_some_and(|op| target_func == &op) { | ||
| if let Some(length) = context.dfg.get_numeric_constant(arguments[0]) { |
There was a problem hiding this comment.
| /// | ||
| /// Note that this pass must be placed before loop unrolling to be useful. | ||
| #[tracing::instrument(level = "trace", skip(self))] | ||
| pub(crate) fn slice_instrinsics_length_optimization(mut self) -> Self { |
There was a problem hiding this comment.
| pub(crate) fn slice_instrinsics_length_optimization(mut self) -> Self { | |
| pub(crate) fn slice_intrinsics_length_optimization(mut self) -> Self { |
| return SimplifyResult::None; | ||
| } | ||
|
|
||
| // slice_insert(length, slice, index, values...) |
| acir(inline) fn main f0 { | ||
| b0(): | ||
| v0 = make_array [Field 2, Field 3] : [Field] | ||
| v1, v2 = call slice_insert(u32 2, v0, u32 1, Field 4) -> (u32, [Field]) |
There was a problem hiding this comment.
Would be good to add a test for the negative case that when we have a dynamic value for the length but a constant array we do not do anything.
Cool! I just read your comment, I kept pushing changes with more "slice intrinsics length" optimizations. If it's fine with you, I think I'd prefer to split this PR into smaller PR, each with one of the proposed optimizations, just so that if there's an issue with just one of them it's easier to revert, etc. Now I'm thinking optimizing I might also introduce a new SSA pass instead of changing |
Yeah I think that would be a good idea.
Whatever you think is best here. As you said the actual |
There was a problem hiding this comment.
ACVM Benchmarks
Details
| Benchmark suite | Current: 0106d13 | Previous: b43153b | Ratio |
|---|---|---|---|
purely_sequential_opcodes |
262673 ns/iter (± 5426) |
263529 ns/iter (± 508) |
1.00 |
perfectly_parallel_opcodes |
231729 ns/iter (± 6656) |
233286 ns/iter (± 2788) |
0.99 |
perfectly_parallel_batch_inversion_opcodes |
2796221 ns/iter (± 1920) |
2797292 ns/iter (± 14705) |
1.00 |
This comment was automatically generated by workflow using github-action-benchmark.
There was a problem hiding this comment.
Test Suite Duration
Details
| Benchmark suite | Current: 0106d13 | Previous: b43153b | Ratio |
|---|---|---|---|
test_report_AztecProtocol_aztec-packages_noir-projects_aztec-nr |
121 s |
116 s |
1.04 |
test_report_AztecProtocol_aztec-packages_noir-projects_noir-contracts |
131 s |
134 s |
0.98 |
test_report_AztecProtocol_aztec-packages_noir-projects_noir-protocol-circuits_crates_blob |
254 s |
273 s |
0.93 |
test_report_AztecProtocol_aztec-packages_noir-projects_noir-protocol-circuits_crates_private-kernel-lib |
242 s |
233 s |
1.04 |
test_report_AztecProtocol_aztec-packages_noir-projects_noir-protocol-circuits_crates_types |
127 s |
126 s |
1.01 |
test_report_noir-lang_noir-bignum_ |
170 s |
152 s |
1.12 |
test_report_noir-lang_noir_bigcurve_ |
357 s |
378 s |
0.94 |
test_report_noir-lang_sha256_ |
14 s |
15 s |
0.93 |
test_report_noir-lang_sha512_ |
14 s |
14 s |
1 |
test_report_zkpassport_noir-ecdsa_ |
2 s |
2 s |
1 |
test_report_zkpassport_noir_rsa_ |
2 s |
2 s |
1 |
This comment was automatically generated by workflow using github-action-benchmark.
There was a problem hiding this comment.
Execution Time
Details
| Benchmark suite | Current: 0106d13 | Previous: b43153b | Ratio |
|---|---|---|---|
private-kernel-inner |
0.011 s |
0.011 s |
1 |
private-kernel-reset |
0.146 s |
0.147 s |
0.99 |
private-kernel-tail |
0.009 s |
0.009 s |
1 |
rollup-block-root-first-empty-tx |
0.003 s |
0.003 s |
1 |
rollup-block-root-single-tx |
0.003 s |
0.003 s |
1 |
rollup-block-root |
0.004 s |
0.004 s |
1 |
rollup-checkpoint-merge |
0.003 s |
0.003 s |
1 |
rollup-checkpoint-root-single-block |
10.9 s |
11.4 s |
0.96 |
rollup-checkpoint-root |
10.9 s |
11.2 s |
0.97 |
rollup-root |
0.004 s |
0.004 s |
1 |
rollup-tx-base-private |
0.302 s |
0.297 s |
1.02 |
rollup-tx-base-public |
0.234 s |
0.244 s |
0.96 |
rollup-tx-merge |
0.002 s |
0.002 s |
1 |
semaphore-depth-10 |
0.008 s |
0.009 s |
0.89 |
sha512-100-bytes |
0.054 s |
0.061 s |
0.89 |
This comment was automatically generated by workflow using github-action-benchmark.
There was a problem hiding this comment.
Opcode count
Details
| Benchmark suite | Current: 0106d13 | Previous: b43153b | Ratio |
|---|---|---|---|
private-kernel-inner |
14544 opcodes |
14544 opcodes |
1 |
private-kernel-reset |
70415 opcodes |
70415 opcodes |
1 |
private-kernel-tail |
11680 opcodes |
11680 opcodes |
1 |
rollup-block-root-first-empty-tx |
1348 opcodes |
1364 opcodes |
0.99 |
rollup-block-root-single-tx |
1033 opcodes |
1048 opcodes |
0.99 |
rollup-block-root |
2409 opcodes |
2409 opcodes |
1 |
rollup-checkpoint-merge |
2130 opcodes |
2130 opcodes |
1 |
rollup-checkpoint-root-single-block |
962003 opcodes |
962015 opcodes |
1.00 |
rollup-checkpoint-root |
963375 opcodes |
963375 opcodes |
1 |
rollup-root |
2630 opcodes |
2630 opcodes |
1 |
rollup-tx-base-private |
263892 opcodes |
263908 opcodes |
1.00 |
rollup-tx-base-public |
245168 opcodes |
245185 opcodes |
1.00 |
rollup-tx-merge |
1486 opcodes |
1486 opcodes |
1 |
semaphore-depth-10 |
5699 opcodes |
5699 opcodes |
1 |
sha512-100-bytes |
13173 opcodes |
13173 opcodes |
1 |
This comment was automatically generated by workflow using github-action-benchmark.
There was a problem hiding this comment.
Compilation Time
Details
| Benchmark suite | Current: 0106d13 | Previous: b43153b | Ratio |
|---|---|---|---|
private-kernel-inner |
1.748 s |
1.812 s |
0.96 |
private-kernel-reset |
7.194 s |
7.378 s |
0.98 |
private-kernel-tail |
1.39 s |
1.334 s |
1.04 |
rollup-block-root-first-empty-tx |
1.364 s |
1.406 s |
0.97 |
rollup-block-root-single-tx |
1.43 s |
1.46 s |
0.98 |
rollup-block-root |
1.48 s |
1.47 s |
1.01 |
rollup-checkpoint-merge |
1.452 s |
1.488 s |
0.98 |
rollup-checkpoint-root-single-block |
214 s |
202 s |
1.06 |
rollup-checkpoint-root |
193 s |
214 s |
0.90 |
rollup-root |
1.52 s |
1.552 s |
0.98 |
rollup-tx-base-private |
19.58 s |
18.98 s |
1.03 |
rollup-tx-base-public |
81.24 s |
81.74 s |
0.99 |
rollup-tx-merge |
1.352 s |
1.394 s |
0.97 |
semaphore-depth-10 |
0.784 s |
0.793 s |
0.99 |
sha512-100-bytes |
1.61 s |
2.008 s |
0.80 |
This comment was automatically generated by workflow using github-action-benchmark.
There was a problem hiding this comment.
Artifact Size
Details
| Benchmark suite | Current: 0106d13 | Previous: b43153b | Ratio |
|---|---|---|---|
private-kernel-inner |
714.3 KB |
714.3 KB |
1 |
private-kernel-reset |
1864 KB |
1864 KB |
1 |
private-kernel-tail |
546.2 KB |
546.2 KB |
1 |
rollup-block-root-first-empty-tx |
179.2 KB |
179.6 KB |
1.00 |
rollup-block-root-single-tx |
177.6 KB |
177.9 KB |
1.00 |
rollup-block-root |
257.9 KB |
257.9 KB |
1 |
rollup-checkpoint-merge |
370.6 KB |
370.6 KB |
1 |
rollup-checkpoint-root-single-block |
27638.6 KB |
27640.2 KB |
1.00 |
rollup-checkpoint-root |
27685.9 KB |
27685.9 KB |
1 |
rollup-root |
411.4 KB |
411.4 KB |
1 |
rollup-tx-base-private |
4906.5 KB |
4909.3 KB |
1.00 |
rollup-tx-base-public |
4554.4 KB |
4555.4 KB |
1.00 |
rollup-tx-merge |
186.1 KB |
186.1 KB |
1 |
semaphore-depth-10 |
570.9 KB |
570.9 KB |
1 |
sha512-100-bytes |
506.3 KB |
506.3 KB |
1 |
This comment was automatically generated by workflow using github-action-benchmark.
There was a problem hiding this comment.
Compilation Memory
Details
| Benchmark suite | Current: 0106d13 | Previous: b43153b | Ratio |
|---|---|---|---|
private-kernel-inner |
254.47 MB |
254.47 MB |
1 |
private-kernel-reset |
493.18 MB |
493.18 MB |
1 |
private-kernel-tail |
244.63 MB |
244.63 MB |
1 |
rollup-block-root-first-empty-tx |
339.37 MB |
339.38 MB |
1.00 |
rollup-block-root-single-tx |
337.41 MB |
337.41 MB |
1 |
rollup-block-root |
340.43 MB |
340.43 MB |
1 |
rollup-checkpoint-merge |
339.76 MB |
339.76 MB |
1 |
rollup-checkpoint-root-single-block |
5910 MB |
5910 MB |
1 |
rollup-checkpoint-root |
5920 MB |
5920 MB |
1 |
rollup-root |
341.31 MB |
341.31 MB |
1 |
rollup-tx-base-private |
1070 MB |
1070 MB |
1 |
rollup-tx-base-public |
2890 MB |
2890 MB |
1 |
rollup-tx-merge |
336.59 MB |
336.59 MB |
1 |
semaphore_depth_10 |
92.18 MB |
92.18 MB |
1 |
sha512_100_bytes |
185.48 MB |
185.48 MB |
1 |
This comment was automatically generated by workflow using github-action-benchmark.
There was a problem hiding this comment.
Execution Memory
Details
| Benchmark suite | Current: 0106d13 | Previous: b43153b | Ratio |
|---|---|---|---|
private-kernel-inner |
253.63 MB |
253.63 MB |
1 |
private-kernel-reset |
287.24 MB |
287.24 MB |
1 |
private-kernel-tail |
243.5 MB |
243.5 MB |
1 |
rollup-block-root |
337.87 MB |
337.87 MB |
1 |
rollup-checkpoint-merge |
336.67 MB |
336.67 MB |
1 |
rollup-checkpoint-root-single-block |
1020 MB |
1020 MB |
1 |
rollup-checkpoint-root |
1020 MB |
1020 MB |
1 |
rollup-root |
337.87 MB |
337.87 MB |
1 |
rollup-tx-base-private |
451.41 MB |
451.42 MB |
1.00 |
rollup-tx-base-public |
466.49 MB |
466.49 MB |
1 |
rollup-tx-merge |
336.13 MB |
336.13 MB |
1 |
semaphore_depth_10 |
73.7 MB |
73.7 MB |
1 |
sha512_100_bytes |
71.96 MB |
71.96 MB |
1 |
This comment was automatically generated by workflow using github-action-benchmark.
|
Closing in favor of #10300 and other upcoming PRs. |
Description
Problem
Resolves #10278
Summary
Alternative to #10279 with what's written in #10279 (comment)
Additional Context
Documentation
Check one:
PR Checklist
cargo fmton default settings.