8000 bench: cover prepared queries in nightly v3 runs (Refs #776) by adityamukho · Pull Request #815 · project-minigraf/minigraf · GitHub
[go: up one dir, main page]

Skip to content
Merged
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
30 changes: 26 additions & 4 deletions 10BC8 .github/workflows/bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ jobs:
filter: "^query/"
file: bench_query.txt

# P02: four existing execute cases plus eight preparation/cursor/slot
# cases. Reserve 4–10 job-minutes pending phase-B timing.
- name: prepared
filter: "^prepared/"
file: bench_prepared.txt
v3_only: true

# ── Sequential: time_travel ─────────────────────────────────────────
- name: time_travel
filter: "^time_travel/"
Expand Down Expand Up @@ -238,10 +245,24 @@ jobs:
sparse-checkout: /.github/bench/
persist-credentials: false

- name: Select benchmark suite for checked-out source
id: suite
env:
V3_ONLY: ${{ matrix.v3_only }}
run: |
if [ "$V3_ONLY" = true ] && [ ! -f benches/minigraf_bench/prepared.rs ]; then
echo "enabled=false" >> "$GITHUB_OUTPUT"
echo 'Skipping v3-only prepared suite: absent from checked-out source.' >> "$GITHUB_STEP_SUMMARY"
else
echo "enabled=true" >> "$GITHUB_OUTPUT"
fi

- name: Install Rust toolchain
if: steps.suite.outputs.enabled == 'true'
uses: dtolnay/rust-toolchain@stable

- name: Cache cargo registry
if: steps.suite.outputs.enabled == 'true'
uses: actions/cache@v6
with:
path: |
Expand All @@ -252,6 +273,7 @@ jobs:
${{ runner.os }}-cargo-bench-

- name: Restore bench target
if: steps.suite.outputs.enabled == 'true'
uses: actions/cache/restore@v6
with:
path: target
Expand All @@ -277,12 +299,12 @@ jobs:
# Select from the shared listing without rerunning any fixture setup.
# Every required matrix route must be nonempty before measurement starts.
- name: Verify selected IDs
if: matrix.name != 'window_rows' || steps.row_frames.outputs.available == 'true'
if: steps.suite.outputs.enabled == 'true' && (matrix.name != 'window_rows' || steps.row_frames.outputs.available == 'true')
run: node .bench-workflow/.github/bench/report.cjs select

- name: Run benchmarks (${{ matrix.name }})
id: benchmarks
if: matrix.name != 'window_rows' || steps.row_frames.outputs.available == 'true'
if: steps.suite.outputs.enabled == 'true' && (matrix.name != 'window_rows' || steps.row_frames.outputs.available == 'true')
run: |
set -o pipefail
CARGO_TERM_COLOR=never cargo bench --bench minigraf_bench -- "$BENCH_FILTER" \
Expand Down Expand Up @@ -473,13 +495,13 @@ jobs:
# Run even when selection, measurement or upload failed. Alerts keep the
# existing two-run reporting policy; API/partial/empty uploads fail the job.
- name: Verify reporting and summarize
if: always() && (matrix.name != 'window_rows' || steps.row_frames.outputs.available == 'true')
if: always() && (steps.suite.outputs.enabled == 'true' && (matrix.name != 'window_rows' || steps.row_frames.outputs.available == 'true'))
env:
BENCHER_OUTCOME: ${{ steps.bencher.outcome }}
run: node .bench-workflow/.github/bench/report.cjs finish

- name: Retain coverage evidence
if: always() && (matrix.name != 'window_rows' || steps.row_frames.outputs.available == 'true')
if: always() && (steps.suite.outputs.enabled == 'true' && (matrix.name != 'window_rows' || steps.row_frames.outputs.available == 'true'))
uses: actions/upload-artifact@v6
with:
name: bench-evidence-${{ strategy.job-index }}
Expand Down
4 changes: 4 additions & 0 deletions benches/minigraf_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

mod helpers;

#[path = "minigraf_bench/prepared.rs"]
mod prepared;

#[cfg(not(target_arch = "wasm32"))]
mod simd_helpers;

Expand Down Expand Up @@ -2149,6 +2152,7 @@ criterion_group!(
bench_concurrent_file,
bench_concurrent_btree_scan,
bench_prepared,
prepared::bench_prepared_extras,
bench_retract,
bench_btree_lookup,
bench_predicate_pushdown,
Expand Down
158 changes: 158 additions & 0 deletions benches/minigraf_bench/prepared.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
//! P02 / G02 of #776: preparation, cursor and typed-slot costs.
//!
//! Eight new 10k cases complement the four existing prepared execute cases.
//! Each execution path has an unprepared control with identical output. Setup,
//! preparation (except prepare_value_lookup) and result checks stay untimed.

use criterion::Criterion;
use minigraf::{BindValue, Cursor, QueryResult, Value};
use std::hint::black_box;
use std::time::Duration;
use uuid::Uuid;

fn rows(result: QueryResult) -> Vec<Vec<Value>> {
match result {
QueryResult::QueryResults { results, .. } => results,
_ => panic!("expected query rows"),
}
}

fn drain(mut cursor: Cursor) -> usize {
let mut count = 0;
while let Some(batch) = cursor.next_batch(256).unwrap() {
count += batch.len();
black_box(batch);
}
count
}

pub fn bench_prepared_extras(c: &mut Criterion) {
let mut group = c.benchmark_group("prepared");
group.sample_size(10);
group.warm_up_time(Duration::from_secs(1));
group.measurement_time(Duration::from_secs(3));

// Keep fixtures inside the selected closures: other nightly suites must
// neither populate this DB nor execute the validation queries.
group.bench_function("prepare_value_lookup/10k", |b| {
let db = super::helpers::populate_in_memory(10_000);
let template = "(query [:find ?e :where [?e :val $val]])";
let prepared = db.prepare(template).unwrap();
assert_eq!(
rows(
prepared
.execute(&[("val", BindValue::Val(Value::Integer(0)))])
.unwrap()
)
.len(),
1
);
b.iter(|| black_box(db.prepare(black_box(template)).unwrap()));
});

group.bench_function("unprepared_value_lookup/10k", |b| {
let db = super::helpers::populate_in_memory(10_000);
let query = "(query [:find ?e :where [?e :val 0]])";
assert_eq!(rows(db.execute(query).unwrap()).len(), 1);
// Pairs with existing prepared/value_lookup/10k, including output
// materialization. Query string construction is not timed.
b.iter(|| black_box(db.execute(black_box(query)).unwrap()));
});

for prepared in [true, false] {
let name = if prepared {
"cursor_drain/10k"
} else {
"unprepared_cursor_drain/10k"
};
group.bench_function(name, |b| {
let db = super::helpers::populate_in_memory(10_000);
let template = "(query [:find ?e :where [?e :val ?v] [(< ?v $threshold)]])";
let literal = "(query [:find ?e :where [?e :val ?v] [(< ?v 5000)]])";
let pq = db.prepare(template).unwrap();
let binds = [("threshold", BindValue::Val(Value::Integer(5_000)))];
assert_eq!(rows(pq.execute(&binds).unwrap()).len(), 5_000);
assert_eq!(drain(pq.query(&binds).unwrap()), 5_000);
assert_eq!(drain(db.query(literal).unwrap()), 5_000);
if prepared {
b.iter(|| black_box(drain(pq.query(black_box(&binds)).unwrap())));
} else {
b.iter(|| black_box(drain(db.query(black_box(literal)).unwrap())));
}
});
}

for prepared in [true, false] {
let name = if prepared {
"count_slots/10k"
} else {
"unprepared_count_slots/10k"
};
group.bench_function(name, |b| {
let db = super::helpers::populate_in_memory(10_000);
let template =
"(query [:find ?v :where [?e :val ?v] :order-by [?v] :limit $n :offset $o])";
let literal =
"(query [:find ?v :where [?e :val ?v] :order-by [?v] :limit 10 :offset 100])";
let pq = db.prepare(template).unwrap();
let binds = [
("n", BindValue::Val(Value::Integer(10))),
("o", BindValue::Val(Value::Integer(100))),
];
let expected: Vec<_> = (100..110).map(|v| vec![Value::Integer(v)]).collect();
assert!(
rows(pq.execute(&binds).unwrap()) == expected,
"prepared page"
);
assert!(
rows(db.execute(literal).unwrap()) == expected,
"unprepared page"
);
if prepared {
b.iter(|| black_box(pq.execute(black_box(&binds)).unwrap()));
} else {
b.iter(|| black_box(db.execute(black_box(literal)).unwrap()));
}
});
}

for prepared in [true, false] {
let name = if prepared {
"time_entity_slots/10k"
} else {
"unprepared_time_entity_slots/10k"
};
group.bench_function(name, |b| {
let db = super::helpers::populate_in_memory(10_000);
// Fixed UUID and valid-time window. A later transaction makes
// :as-of select history instead of using an all-visible bound.
let entity = Uuid::from_u128(776);
db.execute(&format!(
"(transact {{:valid-from \"2001-09-09T01:46:40Z\" :valid-to \"2065-01-24T05:20:00Z\"}} [[#uuid \"{entity}\" :history 1]])"
)).unwrap();
let tx = db.current_tx_count();
db.execute(&format!(
"(transact {{:valid-from \"2001-09-09T01:46:40Z\" :valid-to \"2065-01-24T05:20:00Z\"}} [[#uuid \"{entity}\" :history 2]])"
)).unwrap();
let template = "(query [:find ?v :as-of $tx :valid-at $date :where [$entity :history ?v]])";
let literal = format!(
"(query [:find ?v :as-of {tx} :valid-at \"2033-05-18T03:33:20Z\" :where [#uuid \"{entity}\" :history ?v]])"
);
let pq = db.prepare(template).unwrap();
let binds = [
("tx", BindValue::TxCount(tx)),
("date", BindValue::Timestamp(2_000_000_000_000)),
("entity", BindValue::Entity(entity)),
];
let expected = vec![vec![Value::Integer(1)]];
assert!(rows(pq.execute(&binds).unwrap()) == expected, "prepared history");
assert!(rows(db.execute(&literal).unwrap()) == expected, "unprepared history");
if prepared {
b.iter(|| black_box(pq.execute(black_box(&binds)).unwrap()));
} else {
b.iter(|| black_box(db.execute(black_box(&literal)).unwrap()));
}
});
}
group.finish();
}
Loading
0