-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Various UX and perf improvements. Additional benchmarks (#7)
* Remove page_size dependency and use default bucket size. Fix multi-bucket bug * Forbid unsafe code * Implement From trait in Size * Change RapIdArena to be threadsafe * Change RapId to struct * Small refactor of a test * Add iterator for RapIdArena and tests * Add a workflow that can be use to cache BuildIt builds * Remove coverage badge * Add some alt keys and change colors for better UX on Macs * Add additional DirectoryItem::build() benchmark with more threads * Minor update to readme for Mac/Linux. * Add additional benchmarks to test different thread counts * Add a few test cases for alt keys
- Loading branch information
Showing
22 changed files
with
655 additions
and
274 deletions.
There are no files selected for viewing
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use id_arena::{Arena, Id}; | ||
use space_rs::{ | ||
rapid_arena::{RapId, RapIdArena}, | ||
DirectoryItemType, Size, | ||
}; | ||
use std::{ | ||
ops::{Deref, DerefMut}, | ||
time::Duration, | ||
}; | ||
|
||
const ITEM_COUNT: usize = 100000; | ||
const ITEM_READ_COUNT_PER_ITERATION: usize = 5; | ||
|
||
pub struct StdItem { | ||
pub path_segment: String, | ||
pub item_type: DirectoryItemType, | ||
pub size_in_bytes: Size, | ||
pub child_count: usize, | ||
pub children: Vec<StdItem>, | ||
} | ||
|
||
pub struct BumpaloItem<'a> { | ||
pub path_segment: &'a str, | ||
pub item_type: DirectoryItemType, | ||
pub size_in_bytes: &'a Size, | ||
pub child_count: usize, | ||
pub children: Vec<BumpaloItem<'a>>, | ||
} | ||
|
||
pub struct IdArenaItem { | ||
pub parent: Option<Id<IdArenaItem>>, | ||
pub path_segment: String, | ||
pub item_type: DirectoryItemType, | ||
pub size_in_bytes: Size, | ||
pub child_count: usize, | ||
pub children: Vec<Id<IdArenaItem>>, | ||
} | ||
|
||
pub struct RapIdArenaItem { | ||
pub parent: Option<RapId<RapIdArenaItem>>, | ||
pub path_segment: String, | ||
pub item_type: DirectoryItemType, | ||
pub size_in_bytes: Size, | ||
pub child_count: usize, | ||
pub children: Vec<RapId<RapIdArenaItem>>, | ||
} | ||
|
||
fn bench_arenas_read(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("arenas_read"); | ||
group.measurement_time(Duration::from_secs(3)); | ||
group.warm_up_time(Duration::from_secs(1)); | ||
group.sample_size(100); | ||
|
||
benchmark_std(&mut group); | ||
benchmark_id_arena(&mut group); | ||
benchmark_rapid(&mut group); | ||
|
||
group.finish(); | ||
} | ||
|
||
fn benchmark_std(group: &mut criterion::BenchmarkGroup<'_, criterion::measurement::WallTime>) { | ||
let mut items = Vec::<StdItem>::with_capacity(ITEM_COUNT); | ||
// Alloc | ||
for _ in 0..ITEM_COUNT { | ||
let mut parent = StdItem { | ||
path_segment: "parent".into(), | ||
item_type: DirectoryItemType::Directory, | ||
size_in_bytes: Size::new(1234), | ||
child_count: 1, | ||
children: vec![], | ||
}; | ||
|
||
parent.children.push(StdItem { | ||
path_segment: "child".into(), | ||
item_type: DirectoryItemType::File, | ||
size_in_bytes: Size::new(1234), | ||
child_count: 0, | ||
children: vec![], | ||
}); | ||
|
||
items.push(parent); | ||
} | ||
|
||
group.bench_function("std", |b| { | ||
b.iter(|| { | ||
for i in 0..ITEM_COUNT * ITEM_READ_COUNT_PER_ITERATION { | ||
let _ = &items[i % ITEM_COUNT]; | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
fn benchmark_id_arena(group: &mut criterion::BenchmarkGroup<'_, criterion::measurement::WallTime>) { | ||
let mut arena = Arena::<IdArenaItem>::new(); | ||
let mut ids = vec![]; | ||
|
||
// Alloc | ||
for _ in 0..ITEM_COUNT { | ||
let parent = arena.alloc(IdArenaItem { | ||
parent: None, | ||
path_segment: "parent".to_string(), | ||
item_type: DirectoryItemType::Directory, | ||
size_in_bytes: Size::new(1234), | ||
child_count: 1, | ||
children: vec![], | ||
}); | ||
|
||
let child = arena.alloc(IdArenaItem { | ||
parent: Some(parent), | ||
path_segment: "child".to_string(), | ||
item_type: DirectoryItemType::File, | ||
size_in_bytes: Size::new(1234), | ||
child_count: 0, | ||
children: vec![], | ||
}); | ||
|
||
arena.get_mut(parent).unwrap().children.push(child); | ||
|
||
ids.push(parent); | ||
} | ||
|
||
group.bench_function("id-arena", |b| { | ||
b.iter(|| { | ||
for i in 0..ITEM_COUNT * ITEM_READ_COUNT_PER_ITERATION { | ||
let _ = &arena.get(ids[i % ITEM_COUNT]); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
fn benchmark_rapid(group: &mut criterion::BenchmarkGroup<'_, criterion::measurement::WallTime>) { | ||
let mut arena = RapIdArena::<RapIdArenaItem>::new(); | ||
let mut ids = vec![]; | ||
|
||
// Alloc | ||
for _ in 0..ITEM_COUNT { | ||
let mut parent = arena.alloc(RapIdArenaItem { | ||
parent: None, | ||
path_segment: "parent".to_string(), | ||
item_type: DirectoryItemType::Directory, | ||
size_in_bytes: Size::new(1234), | ||
child_count: 1, | ||
children: vec![], | ||
}); | ||
|
||
let child = arena.alloc(RapIdArenaItem { | ||
parent: Some(parent), | ||
path_segment: "child".to_string(), | ||
item_type: DirectoryItemType::File, | ||
size_in_bytes: Size::new(1234), | ||
child_count: 0, | ||
children: vec![], | ||
}); | ||
|
||
parent.deref_mut().children.push(child); | ||
|
||
ids.push(parent); | ||
} | ||
|
||
group.bench_function("rapid-arena", |b| { | ||
b.iter(|| { | ||
for i in 0..ITEM_COUNT * ITEM_READ_COUNT_PER_ITERATION { | ||
let _ = ids[i % ITEM_COUNT].deref(); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
criterion_group!(benches, bench_arenas_read); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | ||
use space_rs::DirectoryItem; | ||
use std::path::Path; | ||
|
||
const DIRECTORY_PATH: &str = "./tmp.sample"; | ||
|
||
pub fn directory_item_build_x2(c: &mut Criterion) { | ||
let path = &Path::new(DIRECTORY_PATH).to_path_buf(); | ||
|
||
use std::thread::available_parallelism; | ||
let thread_count = available_parallelism().unwrap().get() * 2; | ||
println!("Using {} Rayon threads", thread_count); | ||
|
||
rayon::ThreadPoolBuilder::new() | ||
.num_threads(thread_count) | ||
.build_global() | ||
.unwrap(); | ||
|
||
c.bench_function( | ||
&format!("DirectoryItem::build() x2 on {}", path.display()), | ||
|b| { | ||
b.iter(|| { | ||
black_box(DirectoryItem::build(vec![path.clone()])); | ||
}) | ||
}, | ||
); | ||
} | ||
|
||
criterion_group! { | ||
name = benches; | ||
config = Criterion::default().sample_size(10); | ||
targets = directory_item_build_x2 | ||
} | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | ||
use space_rs::DirectoryItem; | ||
use std::path::Path; | ||
|
||
const DIRECTORY_PATH: &str = "./tmp.sample"; | ||
|
||
pub fn directory_item_build_x3(c: &mut Criterion) { | ||
let path = &Path::new(DIRECTORY_PATH).to_path_buf(); | ||
|
||
use std::thread::available_parallelism; | ||
let thread_count = available_parallelism().unwrap().get() * 3; | ||
println!("Using {} Rayon threads", thread_count); | ||
|
||
rayon::ThreadPoolBuilder::new() | ||
.num_threads(thread_count) | ||
.build_global() | ||
.unwrap(); | ||
|
||
c.bench_function( | ||
&format!("DirectoryItem::build() x3 on {}", path.display()), | ||
|b| { | ||
b.iter(|| { | ||
black_box(DirectoryItem::build(vec![path.clone()])); | ||
}) | ||
}, | ||
); | ||
} | ||
|
||
criterion_group! { | ||
name = benches; | ||
config = Criterion::default().sample_size(10); | ||
targets = directory_item_build_x3 | ||
} | ||
criterion_main!(benches); |
Oops, something went wrong.