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: optimize LWG and NWG #2512

Merged
merged 31 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
ff57b38
Move recursive circuits out of AggregationWrapper struct
0xVolosnikov Jul 26, 2024
64fb5b7
Add comments in prover tests
0xVolosnikov Jul 26, 2024
88e610c
Merge branch 'main' into vv-optimize-lwg-nwg
0xVolosnikov Jul 29, 2024
24ef093
Cargo fmt
0xVolosnikov Jul 29, 2024
cc583c7
Process LWG in batches
0xVolosnikov Jul 29, 2024
7c261a0
Move LWG processing in separate thread
0xVolosnikov Jul 29, 2024
a5105f3
Remove separate thread; cleanup
0xVolosnikov Jul 29, 2024
7b369d5
Fix after merge
0xVolosnikov Jul 30, 2024
69c80f8
Parallelize LWG
0xVolosnikov Jul 30, 2024
9b9c52d
Fix semaphore usage
0xVolosnikov Jul 30, 2024
5a3f20d
Merge branch 'main' into vv-optimize-lwg-nwg
0xVolosnikov Jul 30, 2024
89249e9
Add comments to constants
0xVolosnikov Jul 30, 2024
3ed06aa
Fix todos in basic_test
0xVolosnikov Jul 30, 2024
745461e
Cargo fmt
0xVolosnikov Jul 30, 2024
4b32eb0
Simplify LWG
0xVolosnikov Jul 30, 2024
2dbca20
Parallelize NWG as well
0xVolosnikov Jul 30, 2024
b5b9a04
Update deps
0xVolosnikov Aug 2, 2024
fb75fc2
Address comments
0xVolosnikov Aug 2, 2024
a119262
Cargo.lock
0xVolosnikov Aug 2, 2024
8b6add2
Merge remote-tracking branch 'origin/main' into vv-optimize-lwg-nwg
0xVolosnikov Aug 2, 2024
e7e0235
Hotfix
0xVolosnikov Aug 2, 2024
9899892
Cargo fmt
0xVolosnikov Aug 2, 2024
6468ddd
Use max_circuits_in_flight from config
0xVolosnikov Aug 2, 2024
c2a5e72
Fix
0xVolosnikov Aug 2, 2024
e0694a2
Fix lint issues
0xVolosnikov Aug 2, 2024
0f4db7c
Merge remote-tracking branch 'origin/main' into vv-optimize-lwg-nwg
0xVolosnikov Aug 2, 2024
b61d466
Revert unnessesary Cargo.lock changes
0xVolosnikov Aug 2, 2024
f8c3236
Add comments
0xVolosnikov Aug 2, 2024
1219f7f
Fix lint issues in tests
0xVolosnikov Aug 2, 2024
752c541
Revert blocking spawns
0xVolosnikov Aug 2, 2024
7486f2d
Cleanup
0xVolosnikov Aug 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,578 changes: 803 additions & 775 deletions Cargo.lock

Large diffs are not rendered by default.

18 changes: 11 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -197,19 +197,23 @@ trybuild = "1.0"
vise = "0.1.0"
vise-exporter = "0.1.0"

circuit_sequencer_api_1_3_3 = { package = "circuit_sequencer_api", version = "=0.133.0" }
circuit_sequencer_api_1_4_0 = { package = "circuit_sequencer_api", version = "=0.140.0" }
circuit_sequencer_api_1_4_1 = { package = "circuit_sequencer_api", version = "=0.141.0" }
circuit_sequencer_api_1_4_2 = { package = "circuit_sequencer_api", version = "=0.142.0" }
circuit_sequencer_api_1_5_0 = { package = "circuit_sequencer_api", version = "=0.150.2-rc.1" }
# Here and below:
# We *always* pin the latest version of protocol to disallow accidental changes in the execution logic.
# However, for the historical version of protocol crates, we have lax requirements. Otherwise,
# Bumping a crypto dependency like `boojum` would require us to republish all the historical packages.
circuit_sequencer_api_1_3_3 = { package = "circuit_sequencer_api", version = "0.133" }
circuit_sequencer_api_1_4_0 = { package = "circuit_sequencer_api", version = "0.140" }
circuit_sequencer_api_1_4_1 = { package = "circuit_sequencer_api", version = "0.141" }
circuit_sequencer_api_1_4_2 = { package = "circuit_sequencer_api", version = "0.142" }
circuit_sequencer_api_1_5_0 = { package = "circuit_sequencer_api", version = "=0.150.2-rc.2" }
crypto_codegen = { package = "zksync_solidity_vk_codegen", version = "=0.1.0" }
kzg = { package = "zksync_kzg", version = "=0.150.2-rc.1" }
kzg = { package = "zksync_kzg", version = "=0.150.2-rc.2" }
zk_evm = { version = "=0.133.0" }
zk_evm_1_3_1 = { package = "zk_evm", version = "0.131.0-rc.2" }
zk_evm_1_3_3 = { package = "zk_evm", version = "0.133.0" }
zk_evm_1_4_0 = { package = "zk_evm", version = "0.140.0" }
zk_evm_1_4_1 = { package = "zk_evm", version = "0.141.0" }
zk_evm_1_5_0 = { package = "zk_evm", version = "0.150.0" }
zk_evm_1_5_0 = { package = "zk_evm", version = "=0.150.0" }

# Consensus dependencies.
zksync_concurrency = "=0.1.0-rc.5"
Expand Down
18 changes: 13 additions & 5 deletions core/lib/config/src/configs/fri_witness_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,20 @@ pub struct FriWitnessGeneratorConfig {

pub prometheus_listener_port: Option<u16>,

/// This value corresponds to the maximum number of circuits kept in memory at any given time for a BWG.
/// This value corresponds to the maximum number of circuits kept in memory at any given time for a BWG/LWG/NWG.
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure why we decided to have a single value for all components. They're somewhat different on usage. I don't think we should change this until the first need, but I can see this popping up soon.

Copy link
Member

Choose a reason for hiding this comment

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

We can override the value per-component, so it should be fine.

/// Acts as a throttling mechanism for circuits; the trade-off here is speed vs memory usage.
///
/// BWG:
/// With more circuits in flight, harness does not need to wait for BWG runner to process them.
/// But every single circuit in flight eats memory (up to 50MB).
///
/// LWG/NWG:
/// Each circuit is processed in parallel.
/// Each circuit requires downloading RECURSION_ARITY (32) proofs, each of which can be roughly estimated at 1 MB.
/// So every single circuit should use ~32 MB of RAM + some overhead during serialization
///
/// WARNING: Do NOT change this value unless you're absolutely sure you know what you're doing.
/// It affects the performance and resource usage of BWGs.
/// It affects the performance and resource usage of WGs.
#[serde(default = "FriWitnessGeneratorConfig::default_max_circuits_in_flight")]
pub max_circuits_in_flight: usize,
}
Expand Down Expand Up @@ -97,10 +105,10 @@ impl FriWitnessGeneratorConfig {
self.last_l1_batch_to_process.unwrap_or(u32::MAX)
}

/// 500 was picked as a mid-ground between allowing enough circuits in flight to speed up circuit generation,
/// whilst keeping memory as low as possible. At the moment, max size of a circuit is ~50MB.
/// 500 was picked as a mid-ground between allowing enough circuits in flight to speed up BWG circuit generation,
/// whilst keeping memory as low as possible. At the moment, max size of a circuit in BWG is ~50MB.
/// This number is important when there are issues with saving circuits (network issues, service unavailability, etc.)
/// Maximum theoretic extra memory consumed is up to 25GB (50MB * 500 circuits), but in reality, worse case scenarios are closer to 5GB (the average space distribution).
/// Maximum theoretic extra memory consumed by BWG is up to 25GB (50MB * 500 circuits), but in reality, worse case scenarios are closer to 5GB (the average space distribution).
/// During normal operations (> P95), this will incur an overhead of ~100MB.
const fn default_max_circuits_in_flight() -> usize {
500
Expand Down
Loading
Loading