8000 ci(bench): cover committed history and retraction nightly (Refs #776, P11) by adityamukho · Pull Request #816 · 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
24 changes: 20 additions & 4 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ jobs:
file: bench_prepared.txt
v3_only: true

# ── v3 committed history and retraction shortlist (Refs #776, P11) ──
# 8 history IDs (all shapes, depths 1/2000) + 2 retract IDs (10k).
# Reserve 3–10 job-minutes; phase B must verify the actual allowance.
# btree_lookup/ stays excluded: these pending point/scan cases overlap
# query/point_entity and query/point_attribute (C41 in the audit).
- name: history_retract
filter: "^(point_query_chain_depth/(churned_attr|sibling_attr|attr_scan|churned_attr_as_of)/(1|2000)|retract/(single_fact|batch_100)/10k)$"
file: bench_history_retract.txt
required_case: '"churned_attr_as_of"'

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

# Inspect the actual checkout, including manual branches, tags and SHAs.
- name: Select benchmark suite for checked-out source
id: suite
env:
V3_ONLY: ${{ matrix.v3_only }}
REQUIRED_CASE: ${{ matrix.required_case }}
run: |
enabled=true
if [ "$V3_ONLY" = true ] && [ ! -f benches/minigraf_bench/prepared.rs ]; then
echo "enabled=false" >> "$GITHUB_OUTPUT"
enabled=false
echo 'Skipping v3-only prepared suite: absent from checked-out source.' >> "$GITHUB_STEP_SUMMARY"
else
echo "enabled=true" >> "$GITHUB_OUTPUT"
fi
if [[ -n "$REQUIRED_CASE" ]] && ! git grep -Fq "$REQUIRED_CASE" HEAD -- benches/; then
enabled=false
echo "Skipping $BENCH_SUITE: required v3 benchmark is absent from $BENCH_REF" >> "$GITHUB_STEP_SUMMARY"
fi
echo "enabled=$enabled" >> "$GITHUB_OUTPUT"

- name: Install Rust toolchain
if: steps.suite.outputs.enabled == 'true'
Expand Down Expand Up @@ -356,7 +372,7 @@ jobs:
# that is not reported, goes in the job summary, because the Bencher step
# is continue-on-error; the final coverage check fails upload errors (#776).
- name: Report regression
if: steps.bencher.outcome == 'failure'
if: steps.bencher.outcome == 'failure' && steps.suite.outputs.enabled == 'true'
uses: actions/github-script@v9
env:
SUITE: ${{ matrix.name }}
Expand Down
59 changes: 4 additions & 55 deletions benches/minigraf_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
// cargo bench -- --profile-time 10

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

#[path = "minigraf_bench/prepared.rs"]
mod prepared;
Expand Down Expand Up @@ -1926,59 +1928,6 @@ fn bench_btree_lookup(c: &mut Criterion) {
}
}

// ── point_query_chain_depth (Issue #323) ─────────────────────────────────────
//
// One entity whose :hash is retracted/reasserted `depth` times (exactly one live
// value), plus a never-churned :other on the same entity; checkpointed file DB.

fn bench_point_query_chain_depth(c: &mut Criterion) {
const DEPTHS: &[usize] = &[1, 500, 2000];
const QUERIES: &[(&str, &str)] = &[
(
"churned_attr",
"(query [:find ?v :where [:e/hot :hash ?v]])",
),
(
"sibling_attr",
"(query [:find ?v :where [:e/hot :other ?v]])",
),
("attr_scan", "(query [:find ?v :where [?e :hash ?v]])"),
// tx 2002 asserted h0: an :as-of point query on committed history (#379).
(
"churned_attr_as_of",
"(query [:find ?v :as-of 2002 :valid-at :any-valid-time :where [:e/hot :hash ?v]])",
),
];
for &(name, q) in QUERIES {
let mut group = c.benchmark_group(format!("point_query_chain_depth/{name}"));
group.sample_size(20);
for &depth in DEPTHS {
let dir = tempfile::tempdir().unwrap();
let db = minigraf::Minigraf::open(dir.path().join("b.graph")).unwrap();
for i in 0..2000 {
db.execute(&format!("(transact [[:f/{i} :x {i}]])"))
.unwrap();
}
db.execute("(transact [[:e/hot :other \"o\"]])").unwrap();
db.execute("(transact {:valid-from \"2020-01-01T00:00:00Z\"} [[:e/hot :hash \"h0\"]])")
.unwrap();
for i in 1..depth {
db.execute(&format!("(retract [[:e/hot :hash \"h{}\"]])", i - 1))
.unwrap();
db.execute(&format!(
"(transact {{:valid-from \"2020-01-01T00:00:00Z\"}} [[:e/hot :hash \"h{i}\"]])"
))
.unwrap();
}
db.checkpoint().unwrap();
group.bench_with_input(BenchmarkId::from_parameter(depth), &depth, |b, _| {
b.iter(|| black_box(db.execute(q).unwrap()));
});
}
group.finish();
}
}

// ── query/predicate_pushdown ──────────────────────────────────────────────────

fn bench_predicate_pushdown(c: &mut Criterion) {
Expand Down Expand Up @@ -2156,8 +2105,8 @@ criterion_group!(
bench_retract,
bench_btree_lookup,
bench_predicate_pushdown,
bench_point_query_chain_depth, // Issue #323
bench_simd, // Issue #229
history::bench_point_query_chain_depth, // Issue #323
bench_simd, // Issue #229
);
// Expanded `criterion_main!` so the shared file fixtures are removed at exit.
fn main() {
Expand Down
75 changes: 75 additions & 0 deletions benches/minigraf_bench/history.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
use criterion::{BenchmarkId, Criterion, black_box};

// ── point_query_chain_depth (Issue #323) ─────────────────────────────────────
//
// One entity whose :hash is retracted/reasserted `depth` times (exactly one live
// value), plus a never-churned :other on the same entity; checkpointed file DB.

pub(super) fn bench_point_query_chain_depth(c: &mut Criterion) {
const DEPTHS: &[usize] = &[1, 500, 2000];
const QUERIES: &[(&str, &str)] = &[
(
"churned_attr",
"(query [:find ?v :where [:e/hot :hash ?v]])",
),
(
"sibling_attr",
"(query [:find ?v :where [:e/hot :other ?v]])",
),
("attr_scan", "(query [:find ?v :where [?e :hash ?v]])"),
// tx 2002 asserted h0: an :as-of point query on committed history (#379).
(
"churned_attr_as_of",
"(query [:find ?v :as-of 2002 :valid-at :any-valid-time :where [:e/hot :hash ?v]])",
),
];
for &(name, q) in QUERIES {
let mut group = c.benchmark_group(format!("point_query_chain_depth/{name}"));
group.sample_size(20);
for &depth in DEPTHS {
let fixture = std::sync::OnceLock::new();
group.bench_with_input(BenchmarkId::from_parameter(depth), &depth, |b, _| {
// Skip unselected IDs and reuse one fixture across Criterion's
// warmup and sample callbacks. No fixture work is timed.
let (db, _dir) = fixture.get_or_init(|| {
let dir = tempfile::tempdir().unwrap();
let db = minigraf::Minigraf::open(dir.path().join("b.graph")).unwrap();
for i in 0..2000 {
db.execute(&format!("(transact [[:f/{i} :x {i}]])"))
.unwrap();
}
db.execute("(transact [[:e/hot :other \"o\"]])").unwrap();
db.execute("(transact {:valid-from \"2020-01-01T00:00:00Z\"} [[:e/hot :hash \"h0\"]])")
.unwrap();
for i in 1..depth {
db.execute(&format!("(retract [[:e/hot :hash \"h{}\"]])", i - 1))
.unwrap();
db.execute(&format!(
"(transact {{:valid-from \"2020-01-01T00:00:00Z\"}} [[:e/hot :hash \"h{i}\"]])"
))
.unwrap();
}
db.checkpoint().unwrap();
let minigraf::QueryResult::QueryResults { results, .. } = db.execute(q).unwrap()
else {
panic!("expected history query rows");
};
assert_eq!(results.len(), 1, "history query must return one row");
let expected = match name {
"sibling_attr" => "o".to_owned(),
"churned_attr_as_of" => "h0".to_owned(),
_ => format!("h{}", depth - 1),
};
assert!(
matches!(results.first().and_then(|row| row.first()), Some(minigraf::Value::String(value)) if value == &expected),
"history query must read the intended version"
);
// Close the handle before removing its temporary directory.
(db, dir)
});
b.iter(|| black_box(db.execute(q).unwrap()));
});
}
group.finish();
}
}
Loading
0