From d168d56a9ef16b8597ea3c5b2b63fb47e1af4bad Mon Sep 17 00:00:00 2001 From: Aditya Mukhopadhyay Date: Tue, 3 Nov 2026 10:11:01 +0530 Subject: [PATCH 1/3] bench: make committed history fixtures lazy (Refs #776) Move the existing history benchmarks to a dedicated module and build each checkpointed fixture only inside the selected Criterion closure. Assert the expected current or historical value before timing. Preserve every benchmark ID, scale and measured query. Co-Authored-By: Codex --- benches/minigraf_bench.rs | 59 ++------------------------ benches/minigraf_bench/history.rs | 70 +++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 55 deletions(-) create mode 100644 benches/minigraf_bench/history.rs diff --git a/benches/minigraf_bench.rs b/benches/minigraf_bench.rs index 398df73d44..3faa3f696d 100644 --- a/benches/minigraf_bench.rs +++ b/benches/minigraf_bench.rs @@ -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; @@ -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) { @@ -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() { diff --git a/benches/minigraf_bench/history.rs b/benches/minigraf_bench/history.rs new file mode 100644 index 0000000000..aa9b2ea82f --- /dev/null +++ b/benches/minigraf_bench/history.rs @@ -0,0 +1,70 @@ +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 { + group.bench_with_input(BenchmarkId::from_parameter(depth), &depth, |b, _| { + // Criterion calls this closure only for selected IDs. Keep the + // WAL/fsync fixture work outside b.iter and out of other jobs. + 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" + ); + b.iter(|| black_box(db.execute(q).unwrap())); + }); + } + group.finish(); + } +} From 17b90db12d39a1fb0a1b2e517a80a6f5f30f00c6 Mon Sep 17 00:00:00 2001 From: Aditya Mukhopadhyay Date: Tue, 3 Nov 2026 10:11:18 +0530 Subject: [PATCH 2/3] ci(bench): route committed history and retractions (Refs #776) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add the ten-case P11 history_retract shortlist, explain the pending lookup exclusion, and reserve an unmeasured 3–10 minute nightly allowance. Gate sampling and reporting on benchmark availability in the actual checkout so main-derived refs skip the v3 suite. The default-branch companion is PR #809. Co-Authored-By: Codex --- .github/workflows/bench.yml | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/.github/workflows/bench.yml b/.github/workflows/bench.yml index d8b838241a..00719137f0 100644 --- a/.github/workflows/bench.yml +++ b/.github/workflows/bench.yml @@ -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/" @@ -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' @@ -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 }} From 3de37f47aa18ae4a068ec0e1c9ec5ce0254d6a23 Mon Sep 17 00:00:00 2001 From: Aditya Mukhopadhyay Date: Tue, 3 Nov 2026 10:15:15 +0530 Subject: [PATCH 3/3] bench: retain lazy history fixtures across samples (Refs #776) Criterion re-enters the benchmark closure for warmup and every sample. Hold a per-ID OnceLock outside that closure so selected cases build one fixture and reuse it, preserving the previous setup cost without doing work for excluded IDs. Keep the database alive until before its temporary directory is removed. Co-Authored-By: Codex --- benches/minigraf_bench/history.rs | 69 +++++++++++++++++-------------- 1 file changed, 37 insertions(+), 32 deletions(-) diff --git a/benches/minigraf_bench/history.rs b/benches/minigraf_bench/history.rs index aa9b2ea82f..f8a2ad46c7 100644 --- a/benches/minigraf_bench/history.rs +++ b/benches/minigraf_bench/history.rs @@ -27,41 +27,46 @@ pub(super) fn bench_point_query_chain_depth(c: &mut Criterion) { 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, _| { - // Criterion calls this closure only for selected IDs. Keep the - // WAL/fsync fixture work outside b.iter and out of other jobs. - 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}]])")) + // 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(); - } - 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)) + 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.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" - ); + } + 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())); }); }