Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/engine/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ futures.workspace = true
auto_impl.workspace = true
serde.workspace = true
thiserror.workspace = true
sysinfo.workspace = true

[features]
default = ["std"]
Expand Down
26 changes: 24 additions & 2 deletions crates/engine/primitives/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,29 @@ pub const DEFAULT_RESERVED_CPU_CORES: usize = 1;
const DEFAULT_BLOCK_BUFFER_LIMIT: u32 = 256;
const DEFAULT_MAX_INVALID_HEADER_CACHE_LENGTH: u32 = 256;
const DEFAULT_MAX_EXECUTE_BLOCK_BATCH_SIZE: usize = 4;
const DEFAULT_CROSS_BLOCK_CACHE_SIZE: u64 = 4 * 1024 * 1024 * 1024;
const DEFAULT_CROSS_BLOCK_CACHE_SIZE_PERCENT: f64 = 0.3;

fn get_dynamic_cross_block_cache_size() -> u64 {
#[cfg(feature = "std")]
{
use sysinfo::System;

let mut sys = System::new_all();
sys.refresh_memory();

let total_memory = sys.total_memory();
let used_memory = sys.used_memory();
let available_memory = total_memory - used_memory;
Comment on lines +30 to +32
Copy link
Contributor

Choose a reason for hiding this comment

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


let cache_size = (available_memory as f64 * DEFAULT_CROSS_BLOCK_CACHE_SIZE_PERCENT) as u64;

return cache_size;
}
#[cfg(not(feature = "std"))]
{
4 * 1024 * 1024 * 1024
}
}

/// Determines if the host has enough parallelism to run the payload processor.
///
Expand Down Expand Up @@ -86,7 +108,7 @@ impl Default for TreeConfig {
legacy_state_root: false,
always_compare_trie_updates: false,
disable_caching_and_prewarming: false,
cross_block_cache_size: DEFAULT_CROSS_BLOCK_CACHE_SIZE,
cross_block_cache_size: get_dynamic_cross_block_cache_size(),
has_enough_parallelism: has_enough_parallelism(),
max_proof_task_concurrency: DEFAULT_MAX_PROOF_TASK_CONCURRENCY,
reserved_cpu_cores: DEFAULT_RESERVED_CPU_CORES,
Expand Down
Loading