AztecProtocol / aztec-packages

Apache License 2.0
155 stars 157 forks source link

fix: TS LSP being slow #7181

Closed alexghr closed 5 days ago

alexghr commented 1 week ago

Potential fix for Typescript LSP being slow.

Based on https://github.com/microsoft/TypeScript/issues/42761#issuecomment-778368320 and https://github.com/microsoft/TypeScript/issues/52994

AztecBot commented 1 week ago

Benchmark results

Metrics with a significant change:

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](https://aztec-ci-artifacts.s3.us-east-2.amazonaws.com/benchmarks-v1/pulls/7181.json). ### 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_30_ms | 11,451 (-1%) | 3,064 (-2%) | :warning: 1,368 (**-22%**) | 1,422 (-11%) | 1,450 (-1%) | proof_construction_time_sha256_100_ms | 43,884 (-1%) | 11,753 (-1%) | 5,450 | 5,415 (-1%) | 5,378 | proof_construction_time_poseidon_hash_ms | 78.0 | 34.0 | 34.0 (-3%) | 58.0 | 87.0 (-2%) | proof_construction_time_poseidon_hash_30_ms | 1,516 (-1%) | 416 (-1%) | 200 | 232 (-2%) | 266 (-2%) | proof_construction_time_poseidon_hash_100_ms | 5,756 (-1%) | 1,565 (-1%) | 720 (-1%) | 761 (-2%) | 798 | ### 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 | 1,412 | 1,412 | 1,412 | l1_rollup_calldata_gas | 9,452 | 9,466 | 9,476 | l1_rollup_execution_gas | 610,273 | 610,287 | 610,297 | l2_block_processing_time_in_ms | 752 | 1,430 (+1%) | 2,691 | l2_block_building_time_in_ms | 25,559 (-1%) | 51,341 | 100,553 | l2_block_rollup_simulation_time_in_ms | 25,558 (-1%) | 51,340 | 100,553 | l2_block_public_tx_process_time_in_ms | 21,993 | 47,536 | 96,835 | ### 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 | 7,092 (+2%) | 9,967 (+2%) | node_database_size_in_bytes | 12,181,584 | 16,093,264 (+1%) | 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 | proving_time_in_ms | input_size_in_bytes | output_size_in_bytes | proof_size_in_bytes | num_public_inputs | size_in_gates | | - | - | - | - | - | - | - | - | - | private-kernel-init | 121 | 494 (+1%) | 12,003 (-2%) | 20,634 | 67,190 | 92,352 | 2,819 | 524,288 | private-kernel-inner | 381 | 1,005 (-15%) | 44,536 (-1%) | 94,902 | 67,190 | 92,352 | 2,819 | 2,097,152 | private-kernel-tail | 312 (-2%) | 1,829 (+2%) | 46,465 (+1%) | 99,121 | 71,733 | 14,912 | 399 | 2,097,152 | base-parity | 6.30 (-1%) | 1,981 (+1%) | 2,571 (-1%) | 128 | 64.0 | 2,208 | 2.00 | 131,072 | root-parity | 49.5 (-1%) | 57.6 (-1%) | 33,810 | 27,100 | 64.0 | 2,720 | 18.0 | 2,097,152 | base-rollup | 8,005 | 5,002 (-1%) | 72,165 | 170,330 | 756 | 3,648 | 47.0 | 4,194,304 | root-rollup | 114 (+1%) | 74.1 (-1%) | 19,579 (+1%) | 25,309 | 620 | 3,456 | 41.0 | 1,048,576 | public-kernel-setup | 737 (-6%) | 3,726 | 38,832 | 116,905 | 93,334 | 125,344 | 3,850 | 2,097,152 | public-kernel-app-logic | 632 | 4,845 (-1%) | 39,826 (-1%) | 116,905 | 93,334 | 125,344 | 3,850 | 2,097,152 | public-kernel-tail | 1,416 | 36,681 (+3%) | 165,625 (-1%) | 511,910 | 10,014 | 14,912 | 399 | 8,388,608 | private-kernel-reset-small | 575 (+3%) | 2,199 (+1%) | 40,866 (-1%) | 123,313 | 67,190 | 92,352 | 2,819 | 2,097,152 | public-kernel-teardown | :warning: 655 (**-19%**) | 4,859 (-1%) | 39,866 | 116,905 | 93,334 | 125,344 | 3,850 | 2,097,152 | merge-rollup | 28.9 (-2%) | N/A | N/A | 16,542 | 756 | N/A | N/A | N/A | private-kernel-tail-to-public | N/A | 7,159 (-1%) | 84,935 (+1%) | N/A | N/A | 125,344 | 3,850 | 4,194,304 | Stats on running time collected for app circuits | Function | input_size_in_bytes | output_size_in_bytes | witness_generation_time_in_ms | proof_size_in_bytes | proving_time_in_ms | size_in_gates | num_public_inputs | | - | - | - | - | - | - | - | - | ContractClassRegisterer:register | 1,344 | 9,944 | 426 | N/A | N/A | N/A | N/A | ContractInstanceDeployer:deploy | 1,408 | 9,944 | 40.6 | N/A | N/A | N/A | N/A | MultiCallEntrypoint:entrypoint | 1,920 | 9,944 | 1,806 | N/A | N/A | N/A | N/A | GasToken:deploy | 1,376 | 9,944 | 1,013 (+1%) | N/A | N/A | N/A | N/A | SchnorrAccount:constructor | 1,312 | 9,944 | 1,434 | N/A | N/A | N/A | N/A | SchnorrAccount:entrypoint | 2,304 | 9,944 | 2,859 (+1%) | 16,768 | 50,532 | 2,097,152 | 457 | Token:privately_mint_private_note | 1,280 | 9,944 | 1,701 | N/A | N/A | N/A | N/A | FPC:fee_entrypoint_public | 1,344 | 9,944 | 376 (-1%) | 16,768 | 10,295 (-3%) | 524,288 | 457 | Token:transfer | 1,312 | 9,944 | 4,796 (+5%) | 16,768 | 41,260 (-1%) | 2,097,152 | 457 | AuthRegistry:set_authorized (avm) | 21,043 | N/A | N/A | 87,200 | 1,672 (+1%) | N/A | N/A | FPC:prepare_fee (avm) | 28,495 | N/A | N/A | 88,032 | 4,740 (-4%) | N/A | N/A | Token:transfer_public (avm) | 44,885 | N/A | N/A | 87,754 | 3,516 (-2%) | N/A | N/A | AuthRegistry:consume (avm) | 34,973 | N/A | N/A | 87,616 | 2,772 (-3%) | N/A | N/A | FPC:pay_refund (avm) | 41,394 | N/A | N/A | 88,864 | 16,954 (+1%) | N/A | N/A | Benchmarking:create_note | 1,344 | 9,944 | 1,391 (-1%) | N/A | N/A | N/A | N/A | SchnorrAccount:verify_private_authwit | 1,280 | 9,944 | 82.7 (+14%) | N/A | N/A | N/A | N/A | Token:unshield | 1,376 | 9,944 | 3,844 (+3%) | N/A | N/A | N/A | N/A | FPC:fee_entrypoint_private | 1,376 | 9,944 | 4,777 (+2%) | N/A | N/A | N/A | N/A | ### AVM Simulation Time to simulate various public functions in the AVM. | Function | time_ms | bytecode_size_in_bytes | | - | - | - | GasToken:_increase_public_balance | 70.7 (-4%) | 13,873 | GasToken:set_portal | 16.7 | 3,495 | Token:constructor | 96.0 (+4%) | 24,207 | FPC:constructor | 64.2 (-1%) | 13,893 | GasToken:mint_public | 53.7 (+1%) | 10,241 | Token:mint_public | 67.6 (-3%) | 19,216 | Token:assert_minter_and_mint | 220 (-8%) | 13,034 | AuthRegistry:set_authorized | 33.9 (-28%) | 7,869 | FPC:prepare_fee | 177 (-4%) | 15,129 | Token:transfer_public | 44.4 (-5%) | 31,425 | FPC:pay_refund | 185 (+2%) | 28,061 | Benchmarking:increment_balance | 2,707 | 15,407 | Token:_increase_public_balance | 55.2 (-25%) | 15,089 | FPC:pay_refund_with_shielded_rebate | 304 (-8%) | 29,148 | ### Public DB Access Time to access various public DBs. | Function | time_ms | | - | - | get-nullifier-index | 0.147 (-8%) | ### 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 | 10.5 | 16.9 | 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.606 | 0.519 | N/A | N/A | N/A | N/A | N/A | batch_insert_into_append_only_tree_32_depth_ms | N/A | N/A | 48.9 | 77.4 | 131 | 253 (+3%) | 470 (-1%) | 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.499 | 0.475 | 0.450 | 0.459 (+3%) | 0.438 (-1%) | batch_insert_into_indexed_tree_20_depth_ms | N/A | N/A | 60.1 (+1%) | 112 | 183 | 357 (+1%) | 692 | 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.509 | 0.504 | 0.484 | 0.483 (+1%) | 0.476 | batch_insert_into_indexed_tree_40_depth_ms | N/A | N/A | 73.4 | N/A | N/A | N/A | N/A | batch_insert_into_indexed_tree_40_depth_hash_count | N/A | N/A | 133 | N/A | N/A | N/A | N/A | batch_insert_into_indexed_tree_40_depth_hash_ms | N/A | N/A | 0.523 | 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 | 85,672 | 670,983 | Transaction size based on fee payment method | Metric | | | - | |
spalladino commented 1 week ago

I still get the warning with these changes, though less often. Enabling tsserver tracing shows that we're still loading the full json for the artifacts copied into protocol-contracts and accounts packages. I'll try copying the .d.json.ts files into those packages as well.

spalladino commented 1 week ago

I've added .d.json.ts files in protocol-contracts and accounts, and also removed the json files from the tsconfig include list and replaced them with the declaration ones. I haven't been able to reproduce the "files too big" warning after those changes.

spalladino commented 6 days ago

Build is failing since the artifacts are not found in the dest folder for accounts and protocol-contracts, which makes sense since they don't get copied anymore by tsc as they are not part of the project as per tsconfig. So I'm lifting them out of src and into a shared folder at the root of each package, as we do with the noir-contracts.js package. Let's see if this works!