Skip to content

Commit

Permalink
Merge pull request #542 from nikomatsakis/codspeed
Browse files Browse the repository at this point in the history
Merge Codspeed
  • Loading branch information
nikomatsakis committed Jul 28, 2024
2 parents b37a821 + 5815133 commit cd339fc
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,43 @@ jobs:
- name: Run examples with Miri
run: |
cargo miri run --example calc
benchmarks:
name: Benchmarks
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@master
id: rust-toolchain
with:
toolchain: stable

- name: "Setup codspeed"
uses: taiki-e/install-action@v2
with:
tool: cargo-codspeed

- uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ steps.rust-toolchain.outputs.cachekey }}-${{ hashFiles('**/Cargo.toml') }}
restore-keys: |
${{ runner.os }}-cargo-${{ steps.rust-toolchain.outputs.cachekey }}-
${{ runner.os }}-cargo-
- name: "Build benchmarks"
run: cargo codspeed build

- name: "Run benchmarks"
uses: CodSpeedHQ/action@v2
with:
run: cargo codspeed run
token: ${{ secrets.CODSPEED_TOKEN }}
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ smallvec = "1.0.0"
[dev-dependencies]
annotate-snippets = "0.11.4"
derive-new = "0.6.0"
codspeed-criterion-compat = { version = "2.6.0", default-features = false }
expect-test = "1.4.0"
eyre = "0.6.8"
notify-debouncer-mini = "0.4.1"
Expand All @@ -33,5 +34,10 @@ rustversion = "1.0"
test-log = "0.2.11"
trybuild = "1.0"


[[bench]]
name = "incremental"
harness = false

[workspace]
members = ["components/salsa-macro-rules", "components/salsa-macros"]
54 changes: 54 additions & 0 deletions benches/incremental.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use codspeed_criterion_compat::{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);

0 comments on commit cd339fc

Please sign in to comment.