Skip to content

feat: Signed integer division and modulus in brillig gen#5279

Merged
sirasistant merged 9 commits into
masterfrom
arv/brillig_signed_integers
Mar 18, 2024
Merged

feat: Signed integer division and modulus in brillig gen#5279
sirasistant merged 9 commits into
masterfrom
arv/brillig_signed_integers

Conversation

@sirasistant

@sirasistant sirasistant commented Mar 18, 2024

Copy link
Copy Markdown
Contributor

Removes the signed div opcode since the AVM won't support it and replaces it with the emulated version using unsigned division.

@sirasistant sirasistant changed the title feat: Signed integer division and modulus feat: Signed integer division and modulus in brillig gen Mar 18, 2024
@AztecBot

AztecBot commented Mar 18, 2024

Copy link
Copy Markdown
Collaborator

Benchmark results

No metrics with a significant change found.

Detailed results

All benchmarks are run on txs on the Benchmarking contract on the repository. Each tx consists of a batch call to create_note and increment_balance, which guarantees that each tx has a private call, a nested private call, a public call, and a nested public call, as well as an emitted private note, an unencrypted log, and public storage read and write.

This benchmark source data is available in JSON format on S3 here.

Values are compared against data from master at commit 86e1a864 and shown if the difference exceeds 1%.

L2 block published to L1

Each column represents the number of txs on an L2 block published to L1.

Metric 8 txs 32 txs 64 txs
l1_rollup_calldata_size_in_bytes 5,668 18,820 36,356
l1_rollup_calldata_gas 66,412 238,744 469,112
l1_rollup_execution_gas 647,510 929,102 1,305,292
l2_block_processing_time_in_ms 1,392 (+9%) 4,938 (+4%) 9,033 (+2%)
note_successful_decrypting_time_in_ms 197 (+11%) 499 (+3%) 954
note_trial_decrypting_time_in_ms 107 (+34%) 116 (+16%) 84.9 (+6%)
l2_block_building_time_in_ms 18,152 (+2%) 68,487 136,065 (+2%)
l2_block_rollup_simulation_time_in_ms 8,078 28,530 (-1%) 56,287 (+3%)
l2_block_public_tx_process_time_in_ms 10,053 (+3%) 39,899 79,680 (+1%)

L2 chain processing

Each column represents the number of blocks on the L2 chain where each block has 16 txs.

Metric 5 blocks 10 blocks
node_history_sync_time_in_ms 14,461 (+4%) 26,599 (-4%)
note_history_successful_decrypting_time_in_ms 1,241 (+1%) 2,442 (-2%)
note_history_trial_decrypting_time_in_ms 94.2 (+50%) 157 (-24%)
node_database_size_in_bytes 19,071,056 35,663,952 (-1%)
pxe_database_size_in_bytes 29,859 59,414

Circuits stats

Stats on running time and I/O sizes collected for every circuit run across all benchmarks.

Circuit circuit_simulation_time_in_ms circuit_input_size_in_bytes circuit_output_size_in_bytes
private-kernel-init 282 44,366 28,244
private-kernel-ordering 216 (+1%) 52,868 14,326
base-parity 1,793 (+1%) 128 311
base-rollup 717 (+1%) 165,787 925
root-parity 1,554 (+2%) 1,244 311
root-rollup 63.0 (+1%) 4,487 789
private-kernel-inner 648 (+1%) 73,771 28,244
public-kernel-app-logic 449 (+2%) 35,260 28,215
public-kernel-tail 174 (+2%) 40,926 28,215
merge-rollup 8.32 (+1%) 2,696 925

Tree insertion stats

The duration to insert a fixed batch of leaves into each tree type.

Metric 1 leaves 16 leaves 64 leaves 128 leaves 512 leaves 1024 leaves 2048 leaves 4096 leaves 32 leaves
batch_insert_into_append_only_tree_16_depth_ms 10.0 (-1%) 16.0 (+1%) N/A N/A N/A N/A N/A N/A N/A
batch_insert_into_append_only_tree_16_depth_hash_count 16.8 31.6 N/A N/A N/A N/A N/A N/A N/A
batch_insert_into_append_only_tree_16_depth_hash_ms 0.583 0.495 (+1%) N/A N/A N/A N/A N/A N/A N/A
batch_insert_into_append_only_tree_32_depth_ms N/A N/A 47.0 (+1%) 72.4 (+1%) 234 (+2%) 445 880 1,718 (+4%) N/A
batch_insert_into_append_only_tree_32_depth_hash_count N/A N/A 96.0 159 543 1,055 2,079 4,127 N/A
batch_insert_into_append_only_tree_32_depth_hash_ms N/A N/A 0.482 (+1%) 0.447 (+1%) 0.426 (+2%) 0.416 0.418 0.412 (+4%) N/A
batch_insert_into_indexed_tree_20_depth_ms N/A N/A 53.8 (+2%) 107 (+1%) 337 (+1%) 660 1,315 (+1%) 2,598 (+3%) N/A
batch_insert_into_indexed_tree_20_depth_hash_count N/A N/A 104 207 691 1,363 2,707 5,395 N/A
batch_insert_into_indexed_tree_20_depth_hash_ms N/A N/A 0.478 (+1%) 0.481 (+1%) 0.458 (+1%) 0.454 0.455 (+1%) 0.453 (+3%) N/A
batch_insert_into_indexed_tree_40_depth_ms N/A N/A N/A N/A N/A N/A N/A N/A 61.1 (+1%)
batch_insert_into_indexed_tree_40_depth_hash_count N/A N/A N/A N/A N/A N/A N/A N/A 109
batch_insert_into_indexed_tree_40_depth_hash_ms N/A N/A N/A N/A N/A N/A N/A N/A 0.534 (+1%)

Miscellaneous

Transaction sizes based on how many contract classes are registered in the tx.

Metric 0 registered classes
tx_size_in_bytes 22,012

Transaction processing duration by data writes.

Metric 0 new note hashes 1 new note hashes
tx_pxe_processing_time_ms 3,239 (+2%) 1,755 (+1%)
Metric 0 public data writes 1 public data writes
tx_sequencer_processing_time_ms 11.5 1,251 (+2%)

@sirasistant sirasistant marked this pull request as ready for review March 18, 2024 12:09
ctx.mov_instruction(result.address, num.address);
}
});
self.brillig_context.deallocate_single_addr(max_positive);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not for now but it would be great to use RAII if possible in rust!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah I've to think if I can use smart pointers to make the automatic drop() the compiler inserts at the end of lifetimes to release automatically scratch registers

Comment thread noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_block.rs Outdated

// If result has to be negative, perform two's complement
self.brillig_context.codegen_if(result_is_negative.address, |ctx| {
let zero = ctx.make_constant_instruction(0_usize.into(), result.bit_size);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For the future: in a small-medium contract you'd be saving a lot of instructions if you just intern/pool the constants. That is, if you set them in a register the first time you see it and then just reuse them. (I guess you cannot know from the SSA if they will be modified, but you can do it for the Brillig-codegen ones).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's a little complicated to do it for all internal functions due to linking the functions together, but still possible!

@sirasistant sirasistant merged commit 82f8cf5 into master Mar 18, 2024
@sirasistant sirasistant deleted the arv/brillig_signed_integers branch March 18, 2024 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants