Skip to content

feat: Add reusable procedures to brillig generation#7981

Merged
sirasistant merged 11 commits into
masterfrom
arv/brillig-procedures
Aug 19, 2024
Merged

feat: Add reusable procedures to brillig generation#7981
sirasistant merged 11 commits into
masterfrom
arv/brillig-procedures

Conversation

@sirasistant

@sirasistant sirasistant commented Aug 14, 2024

Copy link
Copy Markdown
Contributor

Changes:

  • Properly typed bytecode labels instead of strings
  • Extracted the register allocator to a trait, added scratch space section
  • Added the concept of procedures, intrinsic functions with data passed through scratch space to avoid stack dumping/restoring
  • Updated the linking process to compile and link procedures if used
  • Added CoW optimized array copy procedure, memcopy procedure and array reverse procedure. They are reused if called more than one time in a single program, reducing bytecode size
Before => After public function sizes

AppSubscription::assert_block_number with size 406 => 389
AppSubscription::assert_not_expired with size 399 => 382
AppSubscription::constructor with size 2476 => 2070
Auth::constructor with size 2012 => 1644
Auth::get_authorized with size 297 => 289
Auth::get_authorized_delay with size 359 => 351
Auth::get_scheduled_authorized with size 282 => 274
Auth::set_authorized with size 1882 => 1526
Auth::set_authorized_delay with size 1801 => 1455
AuthRegistry::_set_authorized with size 519 => 499
AuthRegistry::consume with size 2365 => 1999
AuthRegistry::is_consumable with size 519 => 500
AuthRegistry::is_reject_all with size 355 => 347
AuthRegistry::set_authorized with size 370 => 360
AuthRegistry::set_reject_all with size 206 => 207
AuthWitTest::consume_public with size 1638 => 1389
AvmInitializerTest::constructor with size 1952 => 1594
AvmInitializerTest::read_storage_immutable with size 100 => 103
AvmTest::add_args_return with size 14 => 15
AvmTest::add_storage_map with size 402 => 391
AvmTest::add_u128 with size 130 => 133
AvmTest::assert_nullifier_exists with size 107 => 110
AvmTest::assert_same with size 97 => 100
AvmTest::assert_timestamp with size 103 => 106
AvmTest::assertion_failure with size 111 => 114
AvmTest::check_selector with size 1464 => 1232
AvmTest::create_different_nullifier_in_nested_call with size 246 => 228
AvmTest::create_same_nullifier_in_nested_call with size 244 => 226
AvmTest::debug_logging with size 241 => 236
AvmTest::elliptic_curve_add_and_double with size 81 => 80
AvmTest::emit_nullifier_and_check with size 189 => 192
AvmTest::emit_unencrypted_log with size 640 => 550
AvmTest::get_address with size 12 => 13
AvmTest::get_args_hash with size 17 => 18
AvmTest::get_block_number with size 12 => 13
AvmTest::get_chain_id with size 12 => 13
AvmTest::get_da_gas_left with size 12 => 13
AvmTest::get_fee_per_da_gas with size 12 => 13
AvmTest::get_fee_per_l2_gas with size 12 => 13
AvmTest::get_function_selector with size 12 => 13
AvmTest::get_l2_gas_left with size 12 => 13
AvmTest::get_sender with size 12 => 13
AvmTest::get_storage_address with size 12 => 13
AvmTest::get_timestamp with size 12 => 13
AvmTest::get_transaction_fee with size 12 => 13
AvmTest::get_version with size 12 => 13
AvmTest::keccak_f1600 with size 61 => 61
AvmTest::keccak_hash with size 1220 => 1019
AvmTest::l1_to_l2_msg_exists with size 16 => 17
AvmTest::modulo2 with size 15 => 16
AvmTest::nested_call_to_add with size 363 => 322
AvmTest::nested_call_to_add_with_gas with size 477 => 432
AvmTest::nested_static_call_to_add with size 377 => 336
AvmTest::nested_static_call_to_set_storage with size 257 => 239
AvmTest::new_note_hash with size 10 => 11
AvmTest::new_nullifier with size 10 => 11
AvmTest::note_hash_exists with size 16 => 17
AvmTest::nullifier_collision with size 11 => 12
AvmTest::nullifier_exists with size 16 => 17
AvmTest::pedersen_commit with size 90 => 89
AvmTest::pedersen_hash with size 18 => 19
AvmTest::pedersen_hash_with_index with size 18 => 19
AvmTest::poseidon2_hash with size 1289 => 993
AvmTest::read_storage_list with size 55 => 54
AvmTest::read_storage_map with size 213 => 215
AvmTest::read_storage_single with size 24 => 25
AvmTest::send_l2_to_l1_msg with size 11 => 12
AvmTest::set_opcode_big_field with size 18 => 19
AvmTest::set_opcode_small_field with size 12 => 13
AvmTest::set_opcode_u32 with size 12 => 13
AvmTest::set_opcode_u64 with size 12 => 13
AvmTest::set_opcode_u8 with size 12 => 13
AvmTest::set_read_storage_single with size 33 => 33
AvmTest::set_storage_list with size 21 => 21
AvmTest::set_storage_map with size 220 => 220
AvmTest::set_storage_single with size 18 => 18
AvmTest::sha256_hash with size 46 => 46
AvmTest::test_get_contract_instance with size 339 => 325
AvmTest::test_get_contract_instance_raw with size 82 => 82
AvmTest::to_radix_le with size 162 => 157
AvmTest::u128_addition_overflow with size 469 => 470
AvmTest::u128_from_integer_overflow with size 149 => 149
AvmTest::variable_base_msm with size 92 => 90
Benchmarking::broadcast with size 216 => 217
Benchmarking::increment_balance with size 613 => 572
CardGame::on_card_played with size 1735 => 1594
CardGame::on_cards_claimed with size 1471 => 1413
CardGame::on_game_joined with size 1374 => 1290
CardGame::start_game with size 1913 => 1659
Child::pub_get_value with size 21 => 22
Child::pub_inc_value with size 43 => 42
Child::pub_inc_value_internal with size 216 => 217
Child::pub_set_value with size 30 => 29
Child::set_value_twice_with_nested_first with size 262 => 242
Child::set_value_twice_with_nested_last with size 262 => 242
Child::set_value_with_two_nested_calls with size 226 => 215
Claim::constructor with size 2083 => 1713
Crowdfunding::_check_deadline with size 465 => 438
Crowdfunding::_publish_donation_receipts with size 1821 => 1520
Crowdfunding::init with size 2217 => 1835
DelegatedOn::public_set_value with size 21 => 21
Delegator::public_delegate_set_value with size 291 => 274
DocsExample::get_shared_immutable_constrained_public with size 247 => 250
DocsExample::get_shared_immutable_constrained_public_indirect with size 170 => 166
DocsExample::get_shared_immutable_constrained_public_multiple with size 75 => 74
DocsExample::initialize_public_immutable with size 165 => 166
DocsExample::initialize_shared_immutable with size 165 => 166
DocsExample::spend_public_authwit with size 13 => 14
DocsExample::update_leader with size 177 => 179
EasyPrivateVoting::add_to_tally_public with size 678 => 638
EasyPrivateVoting::constructor with size 1973 => 1613
EasyPrivateVoting::end_vote with size 192 => 184
FeeJuice::_increase_public_balance with size 663 => 633
FeeJuice::balance_of_public with size 372 => 364
FeeJuice::check_balance with size 502 => 484
FeeJuice::claim_public with size 4523 => 3494
FeeJuice::mint_public with size 499 => 479
FeeJuice::set_portal with size 185 => 186
FPC::constructor with size 1952 => 1594
FPC::pay_refund with size 1037 => 934
FPC::pay_refund_with_shielded_rebate with size 1082 => 979
FPC::prepare_fee with size 755 => 666
ImportTest::pub_call_public_fn with size 243 => 225
InclusionProofs::constructor with size 1826 => 1479
InclusionProofs::push_nullifier_public with size 86 => 89
InclusionProofs::test_nullifier_inclusion_from_public with size 90 => 93
KeyRegistry::register_npk_and_ivpk with size 10349 => 8211
KeyRegistry::register_ovpk_and_tpk with size 10351 => 8213
KeyRegistry::rotate_npk_m with size 6797 => 5458
Lending::_borrow with size 6430 => 5782
Lending::_deposit with size 530 => 500
Lending::_repay with size 4112 => 3736
Lending::_withdraw with size 6315 => 5656
Lending::borrow_public with size 515 => 453
Lending::deposit_public with size 1034 => 890
Lending::get_asset with size 464 => 446
Lending::get_assets with size 274 => 265
Lending::get_position with size 2475 => 2277
Lending::init with size 409 => 398
Lending::repay_public with size 936 => 809
Lending::update_accumulator with size 6045 => 5344
Lending::withdraw_public with size 515 => 453
Parent::pub_entry_point with size 144 => 140
Parent::pub_entry_point_twice with size 250 => 229
Parent::public_nested_static_call with size 1588 => 1349
Parent::public_static_call with size 179 => 178
PriceFeed::get_price with size 355 => 347
PriceFeed::set_price with size 216 => 217
PrivateFPC::constructor with size 2083 => 1713
StatefulTest::get_public_value with size 360 => 352
StatefulTest::increment_public_value with size 285 => 276
StatefulTest::increment_public_value_no_init_check with size 217 => 218
StatefulTest::public_constructor with size 2142 => 1748
StaticChild::pub_get_value with size 176 => 179
StaticChild::pub_illegal_inc_value with size 214 => 215
StaticChild::pub_inc_value with size 43 => 42
StaticChild::pub_set_value with size 30 => 29
StaticParent::public_call with size 144 => 140
StaticParent::public_get_value_from_child with size 279 => 255
StaticParent::public_nested_static_call with size 486 => 428
StaticParent::public_static_call with size 179 => 178
Test::assert_public_global_vars with size 454 => 407
Test::consume_message_from_arbitrary_sender_public with size 3580 => 2735
Test::consume_mint_public_message with size 4025 => 3029
Test::create_l2_to_l1_message_arbitrary_recipient_public with size 11 => 12
Test::create_l2_to_l1_message_public with size 24 => 24
Test::dummy_public_call with size 171 => 174
Test::emit_nullifier_public with size 10 => 11
Test::emit_unencrypted with size 258 => 235
Test::is_time_equal with size 17 => 18
TestLog::emit_unencrypted_events with size 3149 => 2555
Token::_increase_public_balance with size 731 => 691
Token::_reduce_total_supply with size 401 => 383
Token::admin with size 227 => 220
Token::assert_minter_and_mint with size 651 => 612
Token::balance_of_public with size 440 => 422
Token::burn_public with size 3763 => 3128
Token::constructor with size 2674 => 2269
Token::is_minter with size 414 => 396
Token::mint_private with size 825 => 789
Token::mint_public with size 946 => 884
Token::public_get_decimals with size 262 => 255
Token::public_get_name with size 251 => 244
Token::public_get_symbol with size 255 => 248
Token::set_admin with size 180 => 172
Token::set_minter with size 357 => 338
Token::shield with size 3950 => 3319
Token::total_supply with size 255 => 248
Token::transfer_public with size 4077 => 3420
TokenBlacklist::_increase_public_balance with size 731 => 691
TokenBlacklist::_reduce_total_supply with size 401 => 383
TokenBlacklist::balance_of_public with size 440 => 422
TokenBlacklist::burn_public with size 4104 => 3447
TokenBlacklist::constructor with size 3844 => 3119
TokenBlacklist::get_roles with size 491 => 472
TokenBlacklist::mint_private with size 905 => 868
TokenBlacklist::mint_public with size 1387 => 1302
TokenBlacklist::shield with size 4291 => 3638
TokenBlacklist::total_supply with size 255 => 248
TokenBlacklist::transfer_public with size 4762 => 4061
TokenBlacklist::update_roles with size 2503 => 2124
TokenBridge::_assert_token_is_same with size 391 => 374
TokenBridge::_call_mint_on_token with size 586 => 531
TokenBridge::claim_public with size 4458 => 3404
TokenBridge::constructor with size 1962 => 1603
TokenBridge::exit_to_l1_public with size 1147 => 1005
TokenBridge::get_portal_address_public with size 112 => 115
TokenBridge::get_token with size 237 => 230
TokenWithRefunds::_increase_public_balance with size 731 => 691
TokenWithRefunds::_reduce_total_supply with size 401 => 383
TokenWithRefunds::admin with size 227 => 220
TokenWithRefunds::assert_minter_and_mint with size 651 => 612
TokenWithRefunds::balance_of_public with size 440 => 422
TokenWithRefunds::burn_public with size 3763 => 3128
TokenWithRefunds::complete_refund with size 774 => 739
TokenWithRefunds::constructor with size 2674 => 2269
TokenWithRefunds::is_minter with size 414 => 396
TokenWithRefunds::mint_private with size 825 => 789
TokenWithRefunds::mint_public with size 946 => 884
TokenWithRefunds::public_get_decimals with size 262 => 255
TokenWithRefunds::public_get_name with size 251 => 244
TokenWithRefunds::public_get_symbol with size 255 => 248
TokenWithRefunds::set_admin with size 180 => 172
TokenWithRefunds::set_minter with size 357 => 338
TokenWithRefunds::shield with size 3950 => 3319
TokenWithRefunds::total_supply with size 255 => 248
TokenWithRefunds::transfer_public with size 4077 => 3420
Uniswap::_approve_bridge_and_exit_input_asset_to_L1 with size 10596 => 8333
Uniswap::_assert_token_is_same with size 697 => 653
Uniswap::constructor with size 1952 => 1594
Uniswap::swap_public with size 6079 => 4988


@AztecBot

AztecBot commented Aug 14, 2024

Copy link
Copy Markdown
Collaborator

Benchmark results

Metrics with a significant change:

  • proof_construction_time_poseidon_hash_ms (4): 48.0 (+41%)
  • avm_simulation_time_ms (FeeJuice:mint_public): 38.0 (-34%)
  • avm_simulation_time_ms (Token:mint_public): 69.8 (+60%)
  • avm_simulation_time_ms (Token:assert_minter_and_mint): 39.7 (-42%)
  • avm_simulation_bytecode_size_in_bytes (FPC:constructor): 18,383 (-18%)
  • avm_simulation_bytecode_size_in_bytes (Token:transfer_public): 39,962 (-16%)
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.

Proof generation

Each column represents the number of threads used in proof generation.

Metric 1 threads 4 threads 16 threads 32 threads 64 threads
proof_construction_time_sha256_ms 5,778 1,555 (-1%) 707 742 (-2%) 770 (+1%)
proof_construction_time_sha256_30_ms 11,866 3,204 1,414 1,446 (+1%) 1,475
proof_construction_time_sha256_100_ms 45,405 12,008 (-2%) 5,438 5,381 (-1%) 5,379
proof_construction_time_poseidon_hash_ms 79.0 (+1%) ⚠️ 48.0 (+41%) 34.0 57.0 (-5%) 87.0 (-1%)
proof_construction_time_poseidon_hash_30_ms 1,534 420 202 231 267
proof_construction_time_poseidon_hash_100_ms 5,654 1,516 677 739 (-3%) 751 (+1%)

L2 block published to L1

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

Metric 4 txs 8 txs 16 txs
l1_rollup_calldata_size_in_bytes 4,324 7,844 14,852
l1_rollup_calldata_gas 49,756 92,494 177,524
l1_rollup_execution_gas 1,383,205 2,130,911 3,957,980
l2_block_processing_time_in_ms 251 (-3%) 441 806 (-1%)
l2_block_building_time_in_ms 9,080 (-2%) 17,726 (-2%) 35,291 (-2%)
l2_block_rollup_simulation_time_in_ms 9,079 (-2%) 17,726 (-2%) 35,291 (-2%)
l2_block_public_tx_process_time_in_ms 7,671 (-2%) 16,208 (-2%) 33,724 (-2%)

L2 chain processing

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

Metric 3 blocks 5 blocks
node_history_sync_time_in_ms 2,942 (+2%) 3,799 (+1%)
node_database_size_in_bytes 12,611,664 16,683,088
pxe_database_size_in_bytes 16,254 26,813

Circuits stats

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

Circuit simulation_time_in_ms witness_generation_time_in_ms input_size_in_bytes output_size_in_bytes proving_time_in_ms
private-kernel-init 84.3 (-12%) 395 (-5%) 21,502 (-1%) 44,858 N/A
private-kernel-inner 157 (-4%) 710 (-1%) 72,180 45,005 N/A
private-kernel-reset-tiny 474 (-8%) 877 (-3%) 65,502 (-1%) 44,844 N/A
private-kernel-tail 200 (-4%) 161 (-4%) 50,606 52,256 N/A
base-parity 5.56 (-1%) N/A 160 96.0 N/A
root-parity 33.3 N/A 69,084 96.0 N/A
base-rollup 2,786 (-3%) N/A 187,817 664 N/A
root-rollup 39.0 N/A 54,525 716 N/A
public-kernel-setup 92.2 (-9%) N/A 103,760 71,222 N/A
public-kernel-app-logic 98.8 (-5%) N/A 103,599 71,222 N/A
public-kernel-tail 559 (-4%) N/A 409,190 16,414 N/A
private-kernel-reset-small 464 (-8%) N/A 66,085 45,629 N/A
private-kernel-tail-to-public 988 (-3%) 652 (-2%) 473,529 (-4%) 1,697 N/A
public-kernel-teardown 86.6 (-8%) N/A 104,005 71,222 N/A
merge-rollup 19.1 N/A 35,742 664 N/A
undefined N/A N/A N/A N/A 65,147 (-1%)

Stats on running time collected for app circuits

Function input_size_in_bytes output_size_in_bytes witness_generation_time_in_ms
ContractClassRegisterer:register 1,344 11,731 343 (-1%)
ContractInstanceDeployer:deploy 1,408 11,731 18.2 (-1%)
MultiCallEntrypoint:entrypoint 1,920 11,731 424 (-1%)
FeeJuice:deploy 1,376 11,731 388
SchnorrAccount:constructor 1,312 11,731 105 (-2%)
SchnorrAccount:entrypoint 2,304 11,731 431 (-1%)
Token:privately_mint_private_note 1,280 11,731 144
FPC:fee_entrypoint_public 1,344 11,731 26.6 (-3%)
Token:transfer 1,312 11,731 283 (-2%)
Benchmarking:create_note 1,344 11,731 104 (+2%)
SchnorrAccount:verify_private_authwit 1,280 11,731 27.6 (-1%)
Token:unshield 1,376 11,731 555 (-1%)
FPC:fee_entrypoint_private 1,376 11,731 759 (-1%)

AVM Simulation

Time to simulate various public functions in the AVM.

Function time_ms bytecode_size_in_bytes
FeeJuice:_increase_public_balance 52.9 (-2%) 7,739 (-5%)
FeeJuice:set_portal 11.6 (-9%) 2,354
Token:constructor 80.4 (-5%) 26,525 (-15%)
FPC:constructor 52.6 (-2%) ⚠️ 18,383 (-18%)
FeeJuice:mint_public ⚠️ 38.0 (-34%) 5,877 (-4%)
Token:mint_public ⚠️ 69.8 (+60%) 10,917 (-7%)
Token:assert_minter_and_mint ⚠️ 39.7 (-42%) 7,512 (-6%)
AuthRegistry:set_authorized 44.6 (-3%) 4,391 (-3%)
FPC:prepare_fee 231 (-3%) 7,712 (-12%)
Token:transfer_public 28.4 (-3%) ⚠️ 39,962 (-16%)
FPC:pay_refund 53.3 (-8%) 10,843 (-10%)
Benchmarking:increment_balance 949 (-2%) 6,929 (-7%)
Token:_increase_public_balance 43.4 (+12%) 8,433 (-6%)
FPC:pay_refund_with_shielded_rebate 70.8 (+6%) 11,392 (-10%)

Public DB Access

Time to access various public DBs.

Function time_ms
get-nullifier-index 0.158

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 256 leaves 512 leaves 1024 leaves
batch_insert_into_append_only_tree_16_depth_ms 2.20 (+2%) 3.96 (+2%) N/A N/A N/A N/A N/A
batch_insert_into_append_only_tree_16_depth_hash_count 16.8 31.7 N/A N/A N/A N/A N/A
batch_insert_into_append_only_tree_16_depth_hash_ms 0.114 (+2%) 0.112 (+2%) N/A N/A N/A N/A N/A
batch_insert_into_append_only_tree_32_depth_ms N/A N/A 11.6 (+1%) 17.7 (-2%) 31.0 (-3%) 59.7 (+2%) 113
batch_insert_into_append_only_tree_32_depth_hash_count N/A N/A 95.9 159 287 543 1,055
batch_insert_into_append_only_tree_32_depth_hash_ms N/A N/A 0.112 (+1%) 0.103 (-2%) 0.101 (-3%) 0.102 (+1%) 0.101
batch_insert_into_indexed_tree_20_depth_ms N/A N/A 14.7 26.1 (+1%) 43.8 (-2%) 83.8 (+2%) 161 (-1%)
batch_insert_into_indexed_tree_20_depth_hash_count N/A N/A 109 207 355 691 1,363
batch_insert_into_indexed_tree_20_depth_hash_ms N/A N/A 0.112 (+1%) 0.105 (+2%) 0.106 (-2%) 0.103 (+2%) 0.101 (-2%)
batch_insert_into_indexed_tree_40_depth_ms N/A N/A 16.5 (+1%) N/A N/A N/A N/A
batch_insert_into_indexed_tree_40_depth_hash_count N/A N/A 132 (-1%) N/A N/A N/A N/A
batch_insert_into_indexed_tree_40_depth_hash_ms N/A N/A 0.106 (+1%) N/A N/A N/A N/A

Miscellaneous

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

Metric 0 registered classes 1 registered classes
tx_size_in_bytes 64,779 668,997

Transaction size based on fee payment method

| Metric | |
| - | |

});
}

/// Computes the size of a parameter if it was flattened

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.

All of these moved from entry_point.rs, since they are not only used in the entrypoint

@sirasistant sirasistant marked this pull request as ready for review August 16, 2024 14:24

@TomAFrench TomAFrench left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Small review, will look on monday.

Comment on lines +76 to 79
/// Returns the usize one register. This will be used to perform arithmetic operations.
pub(crate) fn usize_one() -> MemoryAddress {
MemoryAddress::from(ReservedRegisters::UsizeOne as usize)
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I've noticed a couple of places where we'd benefit from a usize_zero reserved register as well (functions with lots of multiplications, etc)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah this isn't a pure usize as we'd need one for each bitsize which the brillig VM can address. Would still be a saving in general though (at least for commonly used bit sizes.)

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 for the case of zero it's not used as much as usize_one in one specific bitsize, the only downside with having these reserved registers with commonly used values is that they have to be initialized in the entrypoint, presenting a constant cost for programs that don't use them. Maybe if the linker could collect which ones are actually used and only initialize those...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, I think this is worth exploring but we can do this separately (and in the noir repo!)

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.

Yup, it'd be pretty good, we could always reserve the registers and initialize lazily. It should help!

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.

The downside of doing this kind of optimization work in the noir repo is that it's a pain to get bytecode size metrics there for the aztec contracts

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.

Soon we will have a gates diff like we do for ACIR noir-lang/noir#5747 (comment) that we can utilize for testing specific cases. This isn't the aztec contracts, but we can then see the improvements on a sync.

@TomAFrench TomAFrench left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Some nits

Comment thread noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir.rs Outdated
Comment on lines +76 to 79
/// Returns the usize one register. This will be used to perform arithmetic operations.
pub(crate) fn usize_one() -> MemoryAddress {
MemoryAddress::from(ReservedRegisters::UsizeOne as usize)
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, I think this is worth exploring but we can do this separately (and in the noir repo!)

Comment thread noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir.rs Outdated
Comment on lines -105 to -108
// Only deallocate step if we allocated it
if step.is_none() {
self.deallocate_register(step_register);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We're now leaking a register in the case where step != 1, right? Seems like we should still have this.

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 shouldn't since step is either controlled by the caller (we shouldn't deallocate) or usize_one (we shouldn't deallocate either) the if before was because we were allocating within make_usize_constant

sirasistant and others added 2 commits August 19, 2024 16:01
Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com>
@sirasistant sirasistant enabled auto-merge (squash) August 19, 2024 14:39
@github-actions

Copy link
Copy Markdown
Contributor

Changes to circuit sizes

Generated at commit: b927ae14a3f624bbbeb544734b1b9e9138aad4f6, compared to commit: 453a096378df57b0280be9aa52697da434e1a457

🧾 Summary (100% most significant diffs)

Program ACIR opcodes (+/-) % Circuit size (+/-) %
public_kernel_teardown +77,175 ❌ +35.50% +118,498 ❌ +6.60%
public_kernel_setup +1,285 ❌ +0.60% +38,756 ❌ +2.16%
public_kernel_tail +426 ❌ +0.04% +2,298 ❌ +0.02%
public_kernel_app_logic +77,656 ❌ +35.90% -1,199,429 ✅ -66.81%

Full diff report 👇
Program ACIR opcodes (+/-) % Circuit size (+/-) %
public_kernel_teardown 294,539 (+77,175) +35.50% 1,914,480 (+118,498) +6.60%
public_kernel_setup 215,537 (+1,285) +0.60% 1,833,754 (+38,756) +2.16%
public_kernel_tail 995,449 (+426) +0.04% 9,375,596 (+2,298) +0.02%
public_kernel_app_logic 293,995 (+77,656) +35.90% 595,830 (-1,199,429) -66.81%

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.

4 participants