mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-01-22 21:05:11 +00:00
Merge pull request #529 from MichaReiser/incremental-benchmark
Add benchmark for query with many tracked structs
This commit is contained in:
commit
492374de3a
2 changed files with 61 additions and 1 deletions
|
@ -24,6 +24,7 @@ smallvec = "1.0.0"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
annotate-snippets = "0.11.4"
|
annotate-snippets = "0.11.4"
|
||||||
|
criterion = "0.5.1"
|
||||||
derive-new = "0.5.9"
|
derive-new = "0.5.9"
|
||||||
expect-test = "1.4.0"
|
expect-test = "1.4.0"
|
||||||
eyre = "0.6.8"
|
eyre = "0.6.8"
|
||||||
|
@ -33,5 +34,10 @@ rustversion = "1.0"
|
||||||
test-log = "0.2.11"
|
test-log = "0.2.11"
|
||||||
trybuild = "1.0"
|
trybuild = "1.0"
|
||||||
|
|
||||||
|
|
||||||
|
[[bench]]
|
||||||
|
name = "incremental"
|
||||||
|
harness = false
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
members = [ "components/salsa-macro-rules","components/salsa-macros"]
|
members = ["components/salsa-macro-rules", "components/salsa-macros"]
|
||||||
|
|
54
benches/incremental.rs
Normal file
54
benches/incremental.rs
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
|
||||||
|
use salsa::Setter;
|
||||||
|
|
||||||
|
#[salsa::input]
|
||||||
|
struct Input {
|
||||||
|
field: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[salsa::tracked]
|
||||||
|
struct Tracked<'db> {
|
||||||
|
number: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[salsa::tracked(return_ref)]
|
||||||
|
fn index<'db>(db: &'db dyn salsa::Database, input: Input) -> Vec<Tracked<'db>> {
|
||||||
|
(0..input.field(db)).map(|i| Tracked::new(db, i)).collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[salsa::tracked]
|
||||||
|
fn root(db: &dyn salsa::Database, input: Input) -> usize {
|
||||||
|
let index = index(db, input);
|
||||||
|
index.len()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn many_tracked_structs(criterion: &mut Criterion) {
|
||||||
|
criterion.bench_function("many_tracked_structs", |b| {
|
||||||
|
b.iter_batched_ref(
|
||||||
|
|| {
|
||||||
|
let db = salsa::default_database();
|
||||||
|
|
||||||
|
let input = Input::new(&db, 1_000);
|
||||||
|
let input2 = Input::new(&db, 1);
|
||||||
|
|
||||||
|
// prewarm cache
|
||||||
|
let _ = root(&db, input);
|
||||||
|
let _ = root(&db, input2);
|
||||||
|
|
||||||
|
(db, input, input2)
|
||||||
|
},
|
||||||
|
|(db, input, input2)| {
|
||||||
|
// Make a change, but fetch the result for the other input
|
||||||
|
input2.set_field(db).to(2);
|
||||||
|
|
||||||
|
let result = root(db, *input);
|
||||||
|
|
||||||
|
assert_eq!(result, 1_000);
|
||||||
|
},
|
||||||
|
BatchSize::LargeInput,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
criterion_group!(benches, many_tracked_structs);
|
||||||
|
criterion_main!(benches);
|
Loading…
Reference in a new issue