Skip to content

Commit aaa2842

Browse files
committed
Improve overlay performance, particularly for prefix search
1 parent cfce6ae commit aaa2842

File tree

4 files changed

+119
-315
lines changed

4 files changed

+119
-315
lines changed

benches/crud_benchmarks.rs

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ fn bench_account_updates(c: &mut Criterion) {
242242
b.iter_with_setup(
243243
|| {
244244
let db_path = dir.path().join(&file_name);
245-
Database::open(db_path.clone()).unwrap()
245+
Database::open(db_path).unwrap()
246246
},
247247
|db| {
248248
let mut tx = db.begin_rw().unwrap();
@@ -596,15 +596,13 @@ fn bench_state_root_with_overlay(c: &mut Criterion) {
596596
DEFAULT_SETUP_DB_CONTRACT_SIZE,
597597
DEFAULT_SETUP_DB_STORAGE_PER_CONTRACT,
598598
);
599+
let dir = TempDir::new("triedb_bench_state_root_with_overlay").unwrap();
599600
let file_name = base_dir.main_file_name.clone();
601+
copy_files(&base_dir, dir.path()).unwrap();
600602

601603
let mut rng = StdRng::seed_from_u64(SEED_CONTRACT);
602-
// let total_storage_per_address = DEFAULT_SETUP_DB_STORAGE_PER_CONTRACT;
603-
let total_addresses = BATCH_SIZE;
604604
let addresses: Vec<AddressPath> =
605-
(0..total_addresses).map(|_| generate_random_address(&mut rng)).collect();
606-
// let storage_paths_values = generate_storage_paths_values(&addresses,
607-
// total_storage_per_address);
605+
(0..BATCH_SIZE).map(|_| generate_random_address(&mut rng)).collect();
608606

609607
let mut account_overlay_mut = OverlayStateMut::new();
610608
addresses.iter().enumerate().for_each(|(i, addr)| {
@@ -614,33 +612,19 @@ fn bench_state_root_with_overlay(c: &mut Criterion) {
614612
});
615613
let account_overlay = account_overlay_mut.freeze();
616614

617-
// Build overlay state from storage paths and values
618-
// let mut storage_overlay_mut = OverlayStateMut::new();
619-
620-
// for (storage_path, storage_value) in &storage_paths_values {
621-
// // Convert storage path to nibbles for overlay
622-
// let nibbles = storage_path.full_path();
623-
// storage_overlay_mut.insert(nibbles, Some(OverlayValue::Storage(*storage_value)));
624-
// }
625-
626-
// // Freeze the mutable overlay to get an immutable one
627-
// let storage_overlay = storage_overlay_mut.freeze();
628-
629615
group.throughput(criterion::Throughput::Elements(BATCH_SIZE as u64));
630616
group.measurement_time(Duration::from_secs(30));
631617
group.bench_function(BenchmarkId::new("state_root_with_account_overlay", BATCH_SIZE), |b| {
632618
b.iter_with_setup(
633619
|| {
634-
let dir = TempDir::new("triedb_bench_state_root_with_account_overlay").unwrap();
635-
copy_files(&base_dir, dir.path()).unwrap();
636620
let db_path = dir.path().join(&file_name);
637621
Database::open(db_path).unwrap()
638622
},
639623
|db| {
640624
let tx = db.begin_ro().unwrap();
641625

642626
// Compute the root hash with the overlay
643-
let _root_result = tx.compute_root_with_overlay(&account_overlay).unwrap();
627+
let _root_result = tx.compute_root_with_overlay(account_overlay.clone()).unwrap();
644628

645629
tx.commit().unwrap();
646630
},

0 commit comments

Comments
 (0)