From 85fa61fcb4274fbe5a2e0bd07d41be29ff5e368c Mon Sep 17 00:00:00 2001 From: Aditya Mukhopadhyay Date: Wed, 28 Oct 2026 05:50:24 +0530 Subject: [PATCH] docs(perf): verify committed net-assert after #551 (#532) --- CLAUDE.md | 2 +- ROADMAP.md | 2 +- docs/BENCHMARKS.md | 2 +- docs/benchmarks/532-check-rows.rs | 65 ++ docs/benchmarks/532-envelope.json | 767 ++++++++++++++++++++++ docs/benchmarks/532-environment.txt | 88 +++ docs/benchmarks/532-net-assert-audit.md | 211 ++++++ docs/benchmarks/532-net-assert-stacks.txt | 162 +++++ docs/benchmarks/532-profile-summary.json | 202 ++++++ docs/benchmarks/532-profile.sh | 42 ++ docs/benchmarks/532-row-checks.json | 38 ++ docs/benchmarks/532-summarize-profiles.py | 114 ++++ 12 files changed, 1692 insertions(+), 3 deletions(-) create mode 100644 docs/benchmarks/532-check-rows.rs create mode 100644 docs/benchmarks/532-envelope.json create mode 100644 docs/benchmarks/532-environment.txt create mode 100644 docs/benchmarks/532-net-assert-audit.md create mode 100644 docs/benchmarks/532-net-assert-stacks.txt create mode 100644 docs/benchmarks/532-profile-summary.json create mode 100644 docs/benchmarks/532-profile.sh create mode 100644 docs/benchmarks/532-row-checks.json create mode 100644 docs/benchmarks/532-summarize-profiles.py diff --git a/CLAUDE.md b/CLAUDE.md index ae1b580fb1..1ed0eb962d 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -122,7 +122,7 @@ cargo run < demos/demo_negation.txt - `btree.rs`: On-disk B+tree over byte keys (`build_btree`, `cow_update` (copy-on-write inserts and deletes; an emptied leaf or node leaves its parent, an emptied tree is root 0; #550) and `cow_insert`, `LeafCursor` (with `seek`), `prefix_scan`, `get`, `MutexStorageBackend`) - `dict.rs`: `DictReader` (id ↔ UUID/ident, tx timestamps, long values; `uuids_of` walks dense id batches with `LeafCursor` and uses exact scalar reads for sparse/small batches, #530) and `Encoder` (checkpoint-time id assignment and key building) - `value_pages.rs`: append-only value pages for strings over 64 bytes and sets whose element encoding is over 64 bytes (#316; DICT dedup compares bytes, `long_bytes`/`find_long_bytes`) - - `reader.rs`: `OnDiskReader` — covering reads of committed facts (`CommittedReader`, `KeySource`); `live_facts` and the resumable `live_keys` decide net-assert on index keys (#379) among the versions a `TxBound` keeps; `tx_order` (cached per reader), `last_tx_at`, `tx_runs` over the DICT's transactions (#551) + - `reader.rs`: `OnDiskReader` — covering reads of committed facts (`CommittedReader`, `KeySource`); query scans use the resumable `live_keys` to decide net-assert on index keys (#379) among the versions a `TxBound` keeps; `live_facts` is test-only, and production fact-level net-assert handles pending records (#532, superseded by #551); `tx_order` (cached per reader), `last_tx_at`, `tx_runs` over the DICT's transactions (#551) - `verify.rs`: integrity walk for `Minigraf::verify` (tree order, index digests, DICT, page accounting) and the source choice for `rebuild_indexes` (#373) - `meta.rs` / `page.rs` / `freelist.rs`: meta pages A/B, the common page header and allocator (skips quarantined ids), free-list chain - `pins.rs`: `Pins` / `GenerationPin` — generations held by open snapshots and the quarantine of pages checkpoints freed after them (#543) diff --git a/ROADMAP.md b/ROADMAP.md index 8851bce03b..fdf2ea59e5 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -120,7 +120,7 @@ Scope — release-gate testing and documentation: - Persistent fuzz corpus and an operation-sequence target (#387; done on `v3`: corpus caching, weekly `cmin`, the v8 page targets, and the `ops_sequence` and `corrupt_file` targets) - Fault injection across save/WAL/recovery (#390) - Long-running soak test at scale (#392; done on `v3`: `tests/soak_test.rs`, 10M facts and a 5-hour churn weekly, alternating `main` and `v3`) -- Benchmarks at 100K–10M facts and a published performance envelope (#394; on `v3`: `examples/perf_envelope.rs`, results in `docs/BENCHMARKS.md`; follow-ups #528–#532) +- Benchmarks at 100K–10M facts and a published performance envelope (#394; on `v3`: `examples/perf_envelope.rs`, results in `docs/BENCHMARKS.md`; follow-ups #528–#532, with #532 superseded by #551's removal of repeated committed-fact net-assert; [audit and measurements](docs/benchmarks/532-net-assert-audit.md)) - Higher storage/WAL coverage gates and branch-coverage gates (#396; on `v3`: line and branch floors per file in `coverage-thresholds.toml`, checked on every PR) - Durability, recovery and operations guide (#398; done on `v3`: `docs/DURABILITY.md`, also on the docs site; found #535) diff --git a/docs/BENCHMARKS.md b/docs/BENCHMARKS.md index 8a6728f8d0..c615ec9f16 100644 --- a/docs/BENCHMARKS.md +++ b/docs/BENCHMARKS.md @@ -225,7 +225,7 @@ On the executor, before #544 (the executor's query path is gone since #551). `pe - **Up-front materialization (50–60%).** Before matching, the executor turns every live fact of each pattern's attribute into a `Fact` (`selective_fact_fetch` → `live_scan`). A pattern without a bound entity is read in full, so a selective join costs as much as scanning its widest attribute. The streaming engine (#473: `Scan` and `IndexNestedLoopJoin` operators) replaces this. - **DICT lookup per row (26–35%).** `uuid_of` does a B+tree `get` for every row's entity id (#530). - **Bindings as `HashMap` (about 25%).** SipHash insert, lookup and drop per row; #473's columnar batches replace them. -- **`net_asserted_facts` over committed facts that `live_facts` already resolved (about 10%)** (#532). +- **`net_asserted_facts` over committed facts that `live_facts` already resolved (about 10%)** (#532). Superseded by #551's removal of the executor's query path; see the [source audit and fresh envelope/profiles](benchmarks/532-net-assert-audit.md). Pending records still need fact-level net-assert. - **Keyword constants hashed to a UUID per fact (about 8% of the old join)** (#531). The streaming engine resolves pattern constants while planning; see the [post-#551 audit and profiles](benchmarks/531-keyword-constants.md). Expression keyword/ref equality retains a separate per-row conversion described there. - `attribute_value` reads the whole attribute instead of seeking AVET (#518). Fixed by the streaming engine's `Scan` (#544): see below. diff --git a/docs/benchmarks/532-check-rows.rs b/docs/benchmarks/532-check-rows.rs new file mode 100644 index 0000000000..13dc547050 --- /dev/null +++ b/docs/benchmarks/532-check-rows.rs @@ -0,0 +1,65 @@ +//! Independent counts for the two unchecked envelope shapes (#532). +//! Run against the pinned source; this reads the fact log, not Datalog. +use minigraf::{FactFilter, FactOrder, OpenOptions}; +use serde_json::{Value, json}; +use std::path::Path; + +fn main() -> anyhow::Result<()> { + let args: Vec = std::env::args().collect(); + let dir = Path::new(&args[1]); + let report: Value = serde_json::from_str(&std::fs::read_to_string(&args[2])?)?; + let mut checks = Vec::new(); + for scale_report in report["scales"].as_array().unwrap() { + let scale = scale_report["label"].as_str().unwrap(); + let fixture = dir.join(format!("fixture-v1-{scale}.graph")); + let meta: Value = + serde_json::from_str(&std::fs::read_to_string(fixture.with_extension("json"))?)?; + let entities = meta["entities"].as_u64().unwrap(); + let tx_half = meta["tx_half"].as_u64().unwrap(); + let db = OpenOptions::new().read_only(true).path(&fixture).open()?; + let mut log = db.fact_log( + &FactFilter::new() + .tx_range(tx_half..=tx_half) + .order(FactOrder::Storage), + )?; + let cutoff = log.next_batch(1)?.unwrap()[0].tx_id; + drop(log); + let mut ages = db.fact_log( + &FactFilter::new() + .attributes([":age"]) + .order(FactOrder::Storage), + )?; + let mut age_count = 0_u64; + let mut as_of_count = 0_u64; + while let Some(batch) = ages.next_batch(1000)? { + for record in batch { + anyhow::ensure!(record.asserted, "fixture age unexpectedly retracted"); + age_count += 1; + as_of_count += u64::from(record.tx_id <= cutoff); + } + } + anyhow::ensure!(age_count == entities, "fixture age count mismatch"); + let join_count = (0..entities) + .filter(|i| ((i * 7919 + 1) % entities) % 100 == 7) + .count() as u64; + for (name, expected) in [("join_3_scan", join_count), ("as_of_ts_scan", as_of_count)] { + let query = scale_report["queries"] + .as_array() + .unwrap() + .iter() + .find(|q| q["name"] == name) + .unwrap(); + let observed = query["rows"].as_u64().ok_or_else(|| { + anyhow::anyhow!("{scale} {name}: no rows in report (error or cap)") + })?; + anyhow::ensure!( + expected == observed, + "{scale} {name}: expected {expected} rows, observed {observed}" + ); + checks + .push(json!({"scale":scale,"shape":name,"expected":expected,"observed":observed})); + } + } + println!("{}", serde_json::to_string_pretty(&checks)?); + Ok(()) +} diff --git a/docs/benchmarks/532-envelope.json b/docs/benchmarks/532-envelope.json new file mode 100644 index 0000000000..671c26bec4 --- /dev/null +++ b/docs/benchmarks/532-envelope.json @@ -0,0 +1,767 @@ +{ + "budget_secs": 15, + "cap_secs": 60, + "fixture_version": 1, + "minigraf": "2.0.5", + "scales": [ + { + "build": { + "build_ms": 1215.71573, + "entities": 16666, + "facts": 100000, + "file_bytes": 10764288, + "hot_tx_half": 1253, + "peak_rss_kb": 190236, + "tx_half": 126 + }, + "checkpoint_10k_ms": 47.526562, + "checkpoint_1_fact": { + "p50_ms": 0.769354, + "p99_ms": 1.821876, + "runs": 20 + }, + "label": "100k", + "open_ms": 0.173604, + "peak_rss_kb": 20540, + "queries": [ + { + "max_ms": 0.044978, + "name": "point_entity", + "p50_ms": 0.018087, + "p99_ms": 0.041654, + "peak_rss_kb": 5260, + "query": "[:find ?a :where [:p8333 :age ?a]]", + "rows": 1, + "runs": 200 + }, + { + "max_ms": 0.041869, + "name": "attribute_value", + "p50_ms": 0.018715, + "p99_ms": 0.035215, + "peak_rss_kb": 5192, + "query": "[:find ?e :where [?e :name \"p8333\"]]", + "rows": 1, + "runs": 200 + }, + { + "max_ms": 20.092067, + "name": "attribute_scan", + "p50_ms": 12.516093, + "p99_ms": 13.491561, + "peak_rss_kb": 6624, + "query": "[:find ?e ?a :where [?e :age ?a]]", + "rows": 16666, + "runs": 200 + }, + { + "max_ms": 0.118408, + "name": "join_2", + "p50_ms": 0.038674, + "p99_ms": 0.063032, + "peak_rss_kb": 5260, + "query": "[:find ?n :where [:p8333 :follows ?f] [?f :name ?n]]", + "rows": 1, + "runs": 200 + }, + { + "max_ms": 0.25031800000000004, + "name": "join_3_selective", + "p50_ms": 0.209382, + "p99_ms": 0.244454, + "peak_rss_kb": 5400, + "query": "[:find ?n :where [:p8333 :manager ?b] [?s :manager ?b] [?s :name ?n]]", + "rows": 10, + "runs": 200 + }, + { + "max_ms": 50.756571, + "name": "join_3_scan", + "p50_ms": 43.211798, + "p99_ms": 50.091876, + "peak_rss_kb": 14820, + "query": "[:find ?e ?n :where [?e :follows ?f] [?f :group 7] [?f :name ?n]]", + "rows": 167, + "runs": 200 + }, + { + "max_ms": 0.091701, + "name": "join_2_pseudo", + "p50_ms": 0.045187, + "p99_ms": 0.061587, + "peak_rss_kb": 5256, + "query": "[:find ?n ?t :valid-at :any-valid-time :where [:p8333 :follows ?f] [?f :name ?n] [?f :db/tx-count ?t]]", + "rows": 1, + "runs": 200 + }, + { + "max_ms": 3.138433, + "name": "not_probe", + "p50_ms": 2.9506300000000003, + "p99_ms": 3.1013490000000004, + "peak_rss_kb": 6444, + "query": "[:find ?e :where [?e :group 7] (not [?e :age 7])]", + "rows": 148, + "runs": 200 + }, + { + "max_ms": 47.943894, + "name": "not_join_hash", + "p50_ms": 6.090097, + "p99_ms": 6.466007, + "peak_rss_kb": 6564, + "query": "[:find ?e :where [?e :group 7] [?e :age ?a] (not-join [?a] [?f :group 17] [?f :age ?a] [(< ?a 50)])]", + "rows": 72, + "runs": 200 + }, + { + "max_ms": 9.293278, + "name": "or_2", + "p50_ms": 8.752257, + "p99_ms": 9.169069, + "peak_rss_kb": 6680, + "query": "[:find ?e :where [?e :group 7] [?e :age ?a] (or-join [?a] (and [?f :group 17] [?f :age ?a] [(< ?a 30)]) (and [?g :group 27] [?g :age ?a] [(> ?a 60)]))]", + "rows": 111, + "runs": 200 + }, + { + "max_ms": 1.253366, + "name": "recursive_ancestors", + "p50_ms": 1.161515, + "p99_ms": 1.247165, + "peak_rss_kb": 5472, + "query": "[:find ?b :where (boss :p16665 ?b)]", + "rows": 5, + "runs": 200 + }, + { + "max_ms": 207.735901, + "name": "recursive", + "p50_ms": 185.303866, + "p99_ms": 207.735901, + "peak_rss_kb": 44588, + "query": "[:find ?x ?b :where (boss ?x ?b)]", + "rows": 72219, + "runs": 81 + }, + { + "max_ms": 0.050460000000000005, + "name": "as_of", + "p50_ms": 0.019596, + "p99_ms": 0.042886999999999995, + "peak_rss_kb": 5288, + "query": "[:find ?a :as-of 126 :where [:p2083 :age ?a]]", + "rows": 1, + "runs": 200 + }, + { + "max_ms": 0.785977, + "name": "as_of_ts", + "p50_ms": 0.692465, + "p99_ms": 0.780266, + "peak_rss_kb": 5264, + "query": "[:find ?a :as-of \"2026-10-27T23:41:39.268Z\" :where [:p2083 :age ?a]]", + "rows": 1, + "runs": 200 + }, + { + "max_ms": 9.400494, + "name": "as_of_ts_scan", + "p50_ms": 8.176525999999999, + "p99_ms": 9.168143, + "peak_rss_kb": 6268, + "query": "[:find ?e ?a :as-of \"2026-10-27T23:41:39.268Z\" :where [?e :age ?a]]", + "rows": 8400, + "runs": 200 + }, + { + "max_ms": 0.054816, + "name": "valid_at", + "p50_ms": 0.020299, + "p99_ms": 0.034989, + "peak_rss_kb": 5276, + "query": "[:find ?s :valid-at \"2021-06-01T00:00:00Z\" :where [:p8333 :status ?s]]", + "rows": 1, + "runs": 200 + }, + { + "max_ms": 0.398366, + "name": "limit", + "p50_ms": 0.328137, + "p99_ms": 0.37547, + "peak_rss_kb": 5336, + "query": "[:find ?e ?a :where [?e :age ?a] :limit 10]", + "rows": 10, + "runs": 200 + }, + { + "max_ms": 30.758601, + "name": "top_k", + "p50_ms": 23.162474999999997, + "p99_ms": 24.94695, + "peak_rss_kb": 6568, + "query": "[:find ?e ?a :where [?e :age ?a] :order-by [?a :desc] :limit 10]", + "rows": 10, + "runs": 200 + }, + { + "max_ms": 95.708073, + "name": "count", + "p50_ms": 45.753257, + "p99_ms": 53.226040000000005, + "peak_rss_kb": 6852, + "query": "[:find (count ?v) :where [?e ?a ?v]]", + "rows": 1, + "runs": 200 + }, + { + "max_ms": 6.5218430000000005, + "name": "count_grouped", + "p50_ms": 6.177947, + "p99_ms": 6.319084, + "peak_rss_kb": 5952, + "query": "[:find ?g (count ?e) :where [?e :group ?g]]", + "rows": 100, + "runs": 200 + }, + { + "max_ms": 45.148279, + "name": "window", + "p50_ms": 37.130024, + "p99_ms": 44.565559, + "peak_rss_kb": 15268, + "query": "[:find ?e (rank :over (:order-by ?a)) :where [?e :age ?a]]", + "rows": 16666, + "runs": 200 + }, + { + "max_ms": 0.358088, + "name": "hot_current", + "p50_ms": 0.306591, + "p99_ms": 0.334544, + "peak_rss_kb": 5268, + "query": "[:find ?v :where [:hot :counter ?v]]", + "rows": 1, + "runs": 200 + }, + { + "max_ms": 0.41497, + "name": "hot_as_of", + "p50_ms": 0.303105, + "p99_ms": 0.373799, + "peak_rss_kb": 5240, + "query": "[:find ?v :as-of 1253 :valid-at :any-valid-time :where [:hot :counter ?v]]", + "rows": 1, + "runs": 200 + } + ], + "rss_after_open_kb": 2952 + }, + { + "build": { + "build_ms": 11508.805576, + "entities": 166666, + "facts": 1000000, + "file_bytes": 126275584, + "hot_tx_half": 3503, + "peak_rss_kb": 390724, + "tx_half": 1251 + }, + "checkpoint_10k_ms": 120.439574, + "checkpoint_1_fact": { + "p50_ms": 2.0422700000000003, + "p99_ms": 3.111978, + "runs": 20 + }, + "label": "1m", + "open_ms": 0.24697800000000003, + "peak_rss_kb": 20984, + "queries": [ + { + "max_ms": 0.048895, + "name": "point_entity", + "p50_ms": 0.018329, + "p99_ms": 0.035981, + "peak_rss_kb": 5332, + "query": "[:find ?a :where [:p83333 :age ?a]]", + "rows": 1, + "runs": 200 + }, + { + "max_ms": 0.036909, + "name": "attribute_value", + "p50_ms": 0.017002, + "p99_ms": 0.028008, + "peak_rss_kb": 5132, + "query": "[:find ?e :where [?e :name \"p83333\"]]", + "rows": 1, + "runs": 200 + }, + { + "max_ms": 151.755633, + "name": "attribute_scan", + "p50_ms": 136.238625, + "p99_ms": 148.002749, + "peak_rss_kb": 7384, + "query": "[:find ?e ?a :where [?e :age ?a]]", + "rows": 166666, + "runs": 110 + }, + { + "max_ms": 0.058078000000000005, + "name": "join_2", + "p50_ms": 0.036935, + "p99_ms": 0.057378, + "peak_rss_kb": 5304, + "query": "[:find ?n :where [:p83333 :follows ?f] [?f :name ?n]]", + "rows": 1, + "runs": 200 + }, + { + "max_ms": 0.253471, + "name": "join_3_selective", + "p50_ms": 0.203621, + "p99_ms": 0.24701, + "peak_rss_kb": 5160, + "query": "[:find ?n :where [:p83333 :manager ?b] [?s :manager ?b] [?s :name ?n]]", + "rows": 10, + "runs": 200 + }, + { + "max_ms": 1221.750965, + "name": "join_3_scan", + "p50_ms": 1170.473613, + "p99_ms": 1221.750965, + "peak_rss_kb": 47408, + "query": "[:find ?e ?n :where [?e :follows ?f] [?f :group 7] [?f :name ?n]]", + "rows": 1667, + "runs": 13 + }, + { + "max_ms": 0.07728600000000001, + "name": "join_2_pseudo", + "p50_ms": 0.045396, + "p99_ms": 0.06707500000000001, + "peak_rss_kb": 5048, + "query": "[:find ?n ?t :valid-at :any-valid-time :where [:p83333 :follows ?f] [?f :name ?n] [?f :db/tx-count ?t]]", + "rows": 1, + "runs": 200 + }, + { + "max_ms": 35.196805, + "name": "not_probe", + "p50_ms": 27.369343, + "p99_ms": 30.331464, + "peak_rss_kb": 7116, + "query": "[:find ?e :where [?e :group 7] (not [?e :age 7])]", + "rows": 1481, + "runs": 200 + }, + { + "max_ms": 66.01328600000001, + "name": "not_join_hash", + "p50_ms": 54.266563, + "p99_ms": 61.575199999999995, + "peak_rss_kb": 7888, + "query": "[:find ?e :where [?e :group 7] [?e :age ?a] (not-join [?a] [?f :group 17] [?f :age ?a] [(< ?a 50)])]", + "rows": 740, + "runs": 200 + }, + { + "max_ms": 141.217088, + "name": "or_2", + "p50_ms": 82.393987, + "p99_ms": 98.637577, + "peak_rss_kb": 7912, + "query": "[:find ?e :where [?e :group 7] [?e :age ?a] (or-join [?a] (and [?f :group 17] [?f :age ?a] [(< ?a 30)]) (and [?g :group 27] [?g :age ?a] [(> ?a 60)]))]", + "rows": 1112, + "runs": 181 + }, + { + "max_ms": 1.749962, + "name": "recursive_ancestors", + "p50_ms": 1.445837, + "p99_ms": 1.722997, + "peak_rss_kb": 5428, + "query": "[:find ?b :where (boss :p166665 ?b)]", + "rows": 6, + "runs": 200 + }, + { + "max_ms": 2915.399172, + "name": "recursive", + "p50_ms": 2895.6267049999997, + "p99_ms": 2915.399172, + "peak_rss_kb": 359544, + "query": "[:find ?x ?b :where (boss ?x ?b)]", + "rows": 888885, + "runs": 6 + }, + { + "max_ms": 0.037763, + "name": "as_of", + "p50_ms": 0.018756, + "p99_ms": 0.033092, + "peak_rss_kb": 5116, + "query": "[:find ?a :as-of 1251 :where [:p20833 :age ?a]]", + "rows": 1, + "runs": 200 + }, + { + "max_ms": 0.856919, + "name": "as_of_ts", + "p50_ms": 0.805188, + "p99_ms": 0.855254, + "peak_rss_kb": 5340, + "query": "[:find ?a :as-of \"2026-10-27T23:42:42.078Z\" :where [:p20833 :age ?a]]", + "rows": 1, + "runs": 200 + }, + { + "max_ms": 88.80278, + "name": "as_of_ts_scan", + "p50_ms": 79.741556, + "p99_ms": 88.690544, + "peak_rss_kb": 7452, + "query": "[:find ?e ?a :as-of \"2026-10-27T23:42:42.078Z\" :where [?e :age ?a]]", + "rows": 83400, + "runs": 187 + }, + { + "max_ms": 0.049887, + "name": "valid_at", + "p50_ms": 0.02057, + "p99_ms": 0.043552, + "peak_rss_kb": 5312, + "query": "[:find ?s :valid-at \"2021-06-01T00:00:00Z\" :where [:p83333 :status ?s]]", + "rows": 1, + "runs": 200 + }, + { + "max_ms": 0.525366, + "name": "limit", + "p50_ms": 0.353375, + "p99_ms": 0.432058, + "peak_rss_kb": 5196, + "query": "[:find ?e ?a :where [?e :age ?a] :limit 10]", + "rows": 10, + "runs": 200 + }, + { + "max_ms": 300.15279, + "name": "top_k", + "p50_ms": 248.751642, + "p99_ms": 300.15279, + "peak_rss_kb": 6936, + "query": "[:find ?e ?a :where [?e :age ?a] :order-by [?a :desc] :limit 10]", + "rows": 10, + "runs": 60 + }, + { + "max_ms": 480.052449, + "name": "count", + "p50_ms": 466.148623, + "p99_ms": 480.052449, + "peak_rss_kb": 6996, + "query": "[:find (count ?v) :where [?e ?a ?v]]", + "rows": 1, + "runs": 33 + }, + { + "max_ms": 75.590822, + "name": "count_grouped", + "p50_ms": 64.910394, + "p99_ms": 72.795401, + "peak_rss_kb": 7000, + "query": "[:find ?g (count ?e) :where [?e :group ?g]]", + "rows": 100, + "runs": 200 + }, + { + "max_ms": 509.505978, + "name": "window", + "p50_ms": 470.030741, + "p99_ms": 509.505978, + "peak_rss_kb": 102704, + "query": "[:find ?e (rank :over (:order-by ?a)) :where [?e :age ?a]]", + "rows": 166666, + "runs": 32 + }, + { + "max_ms": 0.36025, + "name": "hot_current", + "p50_ms": 0.308309, + "p99_ms": 0.354321, + "peak_rss_kb": 5456, + "query": "[:find ?v :where [:hot :counter ?v]]", + "rows": 1, + "runs": 200 + }, + { + "max_ms": 0.389338, + "name": "hot_as_of", + "p50_ms": 0.296584, + "p99_ms": 0.338388, + "peak_rss_kb": 5396, + "query": "[:find ?v :as-of 3503 :valid-at :any-valid-time :where [:hot :counter ?v]]", + "rows": 1, + "runs": 200 + } + ], + "rss_after_open_kb": 3032 + }, + { + "build": { + "build_ms": 384254.199192, + "entities": 1666666, + "facts": 10000000, + "file_bytes": 1260449792, + "hot_tx_half": 26003, + "peak_rss_kb": 447944, + "tx_half": 12501 + }, + "checkpoint_10k_ms": 314.125626, + "checkpoint_1_fact": { + "p50_ms": 1.0280129999999998, + "p99_ms": 1.731733, + "runs": 20 + }, + "label": "10m", + "open_ms": 0.164738, + "peak_rss_kb": 20824, + "queries": [ + { + "max_ms": 0.036603, + "name": "point_entity", + "p50_ms": 0.019199, + "p99_ms": 0.034373, + "peak_rss_kb": 5232, + "query": "[:find ?a :where [:p833333 :age ?a]]", + "rows": 1, + "runs": 200 + }, + { + "max_ms": 0.055024, + "name": "attribute_value", + "p50_ms": 0.018107, + "p99_ms": 0.033745000000000004, + "peak_rss_kb": 5316, + "query": "[:find ?e :where [?e :name \"p833333\"]]", + "rows": 1, + "runs": 200 + }, + { + "max_ms": 1391.023425, + "name": "attribute_scan", + "p50_ms": 1366.54024, + "p99_ms": 1391.023425, + "peak_rss_kb": 7608, + "query": "[:find ?e ?a :where [?e :age ?a]]", + "rows": 1666666, + "runs": 11 + }, + { + "max_ms": 0.08252100000000001, + "name": "join_2", + "p50_ms": 0.037217, + "p99_ms": 0.068541, + "peak_rss_kb": 5408, + "query": "[:find ?n :where [:p833333 :follows ?f] [?f :name ?n]]", + "rows": 1, + "runs": 200 + }, + { + "max_ms": 0.255473, + "name": "join_3_selective", + "p50_ms": 0.197439, + "p99_ms": 0.24175, + "peak_rss_kb": 5252, + "query": "[:find ?n :where [:p833333 :manager ?b] [?s :manager ?b] [?s :name ?n]]", + "rows": 10, + "runs": 200 + }, + { + "max_ms": 13422.707222, + "name": "join_3_scan", + "p50_ms": 13373.933869, + "p99_ms": 13422.707222, + "peak_rss_kb": 62904, + "query": "[:find ?e ?n :where [?e :follows ?f] [?f :group 7] [?f :name ?n]]", + "rows": 16667, + "runs": 5 + }, + { + "max_ms": 0.102482, + "name": "join_2_pseudo", + "p50_ms": 0.044601, + "p99_ms": 0.065639, + "peak_rss_kb": 5392, + "query": "[:find ?n ?t :valid-at :any-valid-time :where [:p833333 :follows ?f] [?f :name ?n] [?f :db/tx-count ?t]]", + "rows": 1, + "runs": 200 + }, + { + "max_ms": 303.830098, + "name": "not_probe", + "p50_ms": 291.24868999999995, + "p99_ms": 303.830098, + "peak_rss_kb": 7164, + "query": "[:find ?e :where [?e :group 7] (not [?e :age 7])]", + "rows": 14815, + "runs": 52 + }, + { + "max_ms": 647.558721, + "name": "not_join_hash", + "p50_ms": 599.830831, + "p99_ms": 647.558721, + "peak_rss_kb": 9428, + "query": "[:find ?e :where [?e :group 7] [?e :age ?a] (not-join [?a] [?f :group 17] [?f :age ?a] [(< ?a 50)])]", + "rows": 7407, + "runs": 26 + }, + { + "max_ms": 934.43726, + "name": "or_2", + "p50_ms": 920.20309, + "p99_ms": 934.43726, + "peak_rss_kb": 13448, + "query": "[:find ?e :where [?e :group 7] [?e :age ?a] (or-join [?a] (and [?f :group 17] [?f :age ?a] [(< ?a 30)]) (and [?g :group 27] [?g :age ?a] [(> ?a 60)]))]", + "rows": 11111, + "runs": 17 + }, + { + "max_ms": 8.977939000000001, + "name": "recursive_ancestors", + "p50_ms": 2.056958, + "p99_ms": 2.804058, + "peak_rss_kb": 5712, + "query": "[:find ?b :where (boss :p1666665 ?b)]", + "rows": 7, + "runs": 200 + }, + { + "max_ms": 51239.818062, + "name": "recursive", + "p50_ms": 49561.856374, + "p99_ms": 51239.818062, + "peak_rss_kb": 2625200, + "query": "[:find ?x ?b :where (boss ?x ?b)]", + "rows": 10555551, + "runs": 5 + }, + { + "max_ms": 0.038452, + "name": "as_of", + "p50_ms": 0.019308, + "p99_ms": 0.034543, + "peak_rss_kb": 5320, + "query": "[:find ?a :as-of 12501 :where [:p208333 :age ?a]]", + "rows": 1, + "runs": 200 + }, + { + "max_ms": 0.986248, + "name": "as_of_ts", + "p50_ms": 0.915866, + "p99_ms": 0.963379, + "peak_rss_kb": 5360, + "query": "[:find ?a :as-of \"2026-10-27T23:48:12.379Z\" :where [:p208333 :age ?a]]", + "rows": 1, + "runs": 200 + }, + { + "max_ms": 820.419603, + "name": "as_of_ts_scan", + "p50_ms": 807.818617, + "p99_ms": 820.419603, + "peak_rss_kb": 7372, + "query": "[:find ?e ?a :as-of \"2026-10-27T23:48:12.379Z\" :where [?e :age ?a]]", + "rows": 833400, + "runs": 19 + }, + { + "max_ms": 0.04973, + "name": "valid_at", + "p50_ms": 0.020477, + "p99_ms": 0.041831, + "peak_rss_kb": 5312, + "query": "[:find ?s :valid-at \"2021-06-01T00:00:00Z\" :where [:p833333 :status ?s]]", + "rows": 1, + "runs": 200 + }, + { + "max_ms": 0.401898, + "name": "limit", + "p50_ms": 0.336165, + "p99_ms": 0.389736, + "peak_rss_kb": 5092, + "query": "[:find ?e ?a :where [?e :age ?a] :limit 10]", + "rows": 10, + "runs": 200 + }, + { + "max_ms": 2644.193306, + "name": "top_k", + "p50_ms": 2580.7707239999995, + "p99_ms": 2644.193306, + "peak_rss_kb": 7152, + "query": "[:find ?e ?a :where [?e :age ?a] :order-by [?a :desc] :limit 10]", + "rows": 10, + "runs": 6 + }, + { + "max_ms": 4793.986612000001, + "name": "count", + "p50_ms": 4740.718202, + "p99_ms": 4793.986612000001, + "peak_rss_kb": 6992, + "query": "[:find (count ?v) :where [?e ?a ?v]]", + "rows": 1, + "runs": 5 + }, + { + "max_ms": 671.902105, + "name": "count_grouped", + "p50_ms": 645.129281, + "p99_ms": 671.902105, + "peak_rss_kb": 7164, + "query": "[:find ?g (count ?e) :where [?e :group ?g]]", + "rows": 100, + "runs": 24 + }, + { + "max_ms": 6067.961222, + "name": "window", + "p50_ms": 6019.13103, + "p99_ms": 6067.961222, + "peak_rss_kb": 884880, + "query": "[:find ?e (rank :over (:order-by ?a)) :where [?e :age ?a]]", + "rows": 1666666, + "runs": 5 + }, + { + "max_ms": 0.383645, + "name": "hot_current", + "p50_ms": 0.306575, + "p99_ms": 0.351869, + "peak_rss_kb": 5400, + "query": "[:find ?v :where [:hot :counter ?v]]", + "rows": 1, + "runs": 200 + }, + { + "max_ms": 0.351772, + "name": "hot_as_of", + "p50_ms": 0.29909199999999997, + "p99_ms": 0.339522, + "peak_rss_kb": 5380, + "query": "[:find ?v :as-of 26003 :valid-at :any-valid-time :where [:hot :counter ?v]]", + "rows": 1, + "runs": 200 + } + ], + "rss_after_open_kb": 2916 + } + ] +} \ No newline at end of file diff --git a/docs/benchmarks/532-environment.txt b/docs/benchmarks/532-environment.txt new file mode 100644 index 0000000000..eee6ba70ac --- /dev/null +++ b/docs/benchmarks/532-environment.txt @@ -0,0 +1,88 @@ +#532 measurement environment and load snapshots +Source revision: d0ad89c1d6df734afd5d4669ca9139c8f55d7702 +Build: envelope, CARGO_PROFILE_ENVELOPE_DEBUG=2, RUSTFLAGS=-Cforce-frame-pointers=yes +Timing/capture: numactl --cpunodebind=1 --membind=1 +Capture: cycles:u; dwarf,16384; inline expansion; 499 Hz (recursive retry: 249 Hz) +Host identity, hardware inventory, addresses, PIDs, user counts, local times, +uptime durations, installed-service identities and private paths omitted. +Roles: task = build/query/profile commands; observation = collection/probe +commands; background = other listed processes. CPU percentages are raw ps +values from pre/post snapshots, not per-query CPU utilization. + +[environment-before.txt] +Tue Oct 27 23:39:35 UTC 2026 +Load averages: 0.03, 0.01, 0.00 +rustc 1.99.1 (58cf8f9c3 2026-10-13) +binary: rustc +commit-hash: 58cf8f9c35b355199727627d07ae34a4e2846d67 +commit-date: 2026-10-13 +host: x86_64-unknown-linux-gnu +release: 1.99.1 +LLVM version: 23.1.1 +6.8.0-139-generic +schedutil +Top listed CPU consumers (percent; role), entries below 1% omitted: +10.0% observation +2.3% background + +[load-before-envelope.txt] +Tue Oct 27 23:41:38 UTC 2026 +Load averages: 0.79, 0.55, 0.22 +Top listed CPU consumers (percent; role), entries below 1% omitted: +11.1% observation +2.3% background + +[load-after-envelope.txt] +Wed Oct 28 00:02:54 UTC 2026 +Load averages: 1.02, 1.18, 1.04 +Top listed CPU consumers (percent; role), entries below 1% omitted: +2.3% background + +[load-before-profiles.txt] +Wed Oct 28 00:03:28 UTC 2026 +Load averages: 0.84, 1.12, 1.02 +Top listed CPU consumers (percent; role), entries below 1% omitted: +300% observation +2.3% background + +[load-after-profiles.txt] +Wed Oct 28 00:06:22 UTC 2026 +Load averages: 2.31, 1.49, 1.16 +Top listed CPU consumers (percent; role), entries below 1% omitted: +2.3% background + +[load-before-recursive-retry.txt] +Wed Oct 28 00:07:33 UTC 2026 +Load averages: 0.66, 1.16, 1.07 +Top listed CPU consumers (percent; role), entries below 1% omitted: +300% observation +8.8% observation +2.3% background + +[load-after-recursive-retry.txt] +Wed Oct 28 00:08:04 UTC 2026 +Load averages: 0.79, 1.14, 1.06 +Top listed CPU consumers (percent; role), entries below 1% omitted: +2.3% background + +[toolchain-after] +rustc 1.99.1 (58cf8f9c3 2026-10-13) +binary: rustc +commit-hash: 58cf8f9c35b355199727627d07ae34a4e2846d67 +commit-date: 2026-10-13 +host: x86_64-unknown-linux-gnu +release: 1.99.1 +LLVM version: 23.1.1 +6.8.0-139-generic +schedutil + +[sha256] +Cargo.lock: b03965119fd8ce5b5cf3ad3d37fb194ffeae24b6a862a0c85ae8fbcb6833ee77 +perf_envelope.rs: 6b8571b6aef0ee2d04523597002d3bd2a55c50270a55a2ec4f3366ce2fa4566e +check_532_rows.rs: ba0c4ddf57b09f95331d8e7aeb61a678dcc0bb0033b8efb2e8b3197f565abab9 +perf_envelope: c4df88de77f99e20bc674eed2f2e6aa94e477bd261a68d1f9f46d5ea8eeacad7 + +[fixture-WAL-bytes] +100k: absent +1m: absent +10m: absent diff --git a/docs/benchmarks/532-net-assert-audit.md b/docs/benchmarks/532-net-assert-audit.md new file mode 100644 index 0000000000..7095017d8b --- /dev/null +++ b/docs/benchmarks/532-net-assert-audit.md @@ -0,0 +1,211 @@ +# Committed net-assert after the streaming engine (#532) + +Source audited: [`v3` at `d0ad89c1d`](https://github.com/project-minigraf/minigraf/tree/d0ad89c1d6df734afd5d4669ca9139c8f55d7702) +(2026-10-28). #551 removed `filter_facts_for_query` and the old rule evaluator. +Production queries read checkpointed facts through the engine's covering +key scans. No surviving production call to `net_asserted_facts` takes those +committed scan results. This supersedes #532's original repeated hashing of +committed facts; pending records still need fact-level net-assert. + +## Source audit + +Here, **committed** means the checkpointed keys in a snapshot's committed +reader. A durable transaction may still be in the snapshot's **pending** store, +including records replayed from a WAL. These terms describe the query's read +sources, not whether a transaction has committed durably. A later checkpoint +does not change an already-open snapshot's sources. Inside a large transaction, +the same committed-reader interface points at working trees, as described below. + +Line references describe the pinned source; paths are relative to `src/`. + +| Path | Evidence | +|---|---| +| Plain queries and cursors | `query/datalog/executor.rs:299,308,315`: collecting and cursor entry points use `open_query`, which calls `engine::plan` and `engine::open`; rule queries use `open_rule_query` (line 354). There is no legacy fallback. | +| Prepared queries | `query/datalog/prepared.rs:105,122,135,145`: substitute slots, set one snapshot, then call the same executor's `execute` or `open`. | +| Rules, including recursive/semi-naive evaluation | `query/engine/mod.rs:200` opens rules; `query/engine/recursive.rs:53,103,151` evaluates strata, scans stored rows with the ordinary `Scan`, and builds full/delta body operator trees. Derived relations hold cells, not a committed-plus-pending `Vec` passed through the old filter. | +| Joins, negation, disjunction, aggregates and windows | `query/engine/mod.rs:297` builds the operators. Joins and the body trees of `AntiJoin` and `Union` use the same scan implementation; aggregates/windows consume their batches. None directly calls `net_asserted_facts`; their scans can reach it through the pending path below. | +| Committed scans and pending shadows | `query/engine/scan.rs:404,454` reads `KeyFact`s with `KeySource::live_keys`; `storage/reader.rs:156,408` decides net-assert on index keys before decoding surviving keys. `scan.rs:759` builds the shadow set from pending records only; value probes do the same at lines 274–325. Valid-time and shadow checks filter surviving keys, without rehashing them as facts. When the shadow set is nonempty, each surviving key still needs an EAV-prefix hash lookup (lines 470–474); fully checkpointed fixtures have no such pending shadow. | +| Pending records | `graph/storage.rs:505,577,614`: `pending_live` walks pending/staged `(entity, attribute)` runs, and `flush_run` calls `net_asserted_facts`. `PendingView::fact` (line 223) reads only those stores. This is the only production call site of `net_asserted_facts`. | +| Transaction queries | `db.rs:1777,1795`: small transactions add staged facts to the pending view (`graph/storage.rs:307,329`). Large transactions use `storage/persistent_facts/large_tx.rs:218`'s `OnDiskReader` over working trees, with the snapshot's pending length cleared (`graph/storage.rs:319`). Both use the same engine. | +| WAL-backed and replayed records | `db.rs:687` skips WAL entries already in the checkpoint and loads newer entries through `FactStorage::load_facts` (`graph/storage.rs:793`), which appends to pending. Fact-level net-assert there is necessary, not a second pass over committed scan output. | +| Temporal queries | `query/engine/mod.rs:178` resolves counter/timestamp bounds for both plain and rule reads. `Snapshot::tx_bound` (`graph/storage.rs:340`) uses a counter bound for monotonic timestamps or committed transaction ranges plus pending timestamp checks for irregular timestamps. `live_keys` applies that bound during the index walk; `scan.rs:888,896` applies valid-time visibility afterward. No historical fallback uses fact-level filtering of committed output. | +| Browser and optional builds | `browser/mod.rs:136,312,335` uses the same executor for execute, prepared and cursor APIs. The core dispatch/scan code has no alternate WASM query path. Cargo's `wasm` feature is a deprecated no-op; `browser` adds browser APIs/storage; `test-hooks` adds test controls, not another engine. This is a static cfg audit, not a new WASM build or browser runtime test. | + +`CommittedReader::live_facts` (`storage/mod.rs:401`), +`OnDiskReader::live_facts` (`storage/reader.rs:480`), the snapshot helper that +combines live facts (`graph/storage.rs:454`) and `get_current_value` +(`graph/storage.rs:1335`'s `cfg(test)` impl) are test-only. Of these, only the +trait's default `live_facts` and `get_current_value` directly call +`net_asserted_facts`; the on-disk implementation resolves live keys, and the +snapshot helper delegates to it. None ships in the production query path. +The remaining direct calls in `persistent_facts.rs` and the storage test +module are tests. + +An empty pending walk still ends in `flush_run(Vec::new())`, which can call +`net_asserted_facts` with no input. Its symbol may therefore occur in a profile +of a fully checkpointed fixture. That is distinct from hashing every committed +row, and this task does not change it. + +## Measurements + +**Date:** 2026-10-28. Idle benchmark server, Linux 6.8.0-139-generic, +Rust 1.99.1; `envelope` profile (opt-level 3), +`CARGO_PROFILE_ENVELOPE_DEBUG=2`, `RUSTFLAGS='-Cforce-frame-pointers=yes'`. +CPU and memory were bound to NUMA node 1 for timings and captures; compilation +used the whole host beforehand. No build/test ran alongside timings. Queries +drained read-only cursors over checkpointed fixtures with warm page caches. +Pre/post toolchain, governor and process/load observations are retained in the +[environment record](532-environment.txt). Host identity and private hardware +details are omitted. + +The [raw envelope](532-envelope.json) covers all 23 shapes at each scale, +including storage and RSS. All 69 records completed without errors or caps, +with at least five timed runs each. Its `minigraf: 2.0.5` field comes from the unreleased branch's Cargo +manifest; the measured code is the revision above, not the published release. +These are absolute measurements, not a paired A/B against the old executor's +historical 10% profile or the earlier [#551 snapshot](../BENCHMARKS.md#executor-removal-551). +That snapshot predates later optimizations such as #530, and this build records +its own frame-pointer/debuginfo flags. No numerical 10% speedup is inferred. + +The envelope's built-in count assertions cover all shapes except +`join_3_scan` and `as_of_ts_scan`. The retained checker validates those two: +the [six independent checks](532-row-checks.json) all match. The join count is the fixture generator's arithmetic mapping +`((i * 7919 + 1) % E) % 100 == 7`, summed over `0 <= i < E`, independently +of the query engine; it does not independently check the stored `:follows` +and `:group` records. The timestamp scan count reads raw `:age` records with +`fact_log`, keeping `tx_id <=` the fixture's `tx_half` timestamp, including +transactions sharing that millisecond. This log uses `LogSource::walk`, +not the query engine's `live_keys` path. With fewer than 100 timed runs, +the envelope's p99 is the maximum sample. + +| Scale | Shape | Rows | Runs | p50 (ms) | p99 (ms) | Peak RSS (MiB) | +|---|---|---:|---:|---:|---:|---:| +| 100k | `attribute_scan` | 16,666 | 200 | 12.516 | 13.492 | 6.5 | +| 100k | `join_3_selective` | 10 | 200 | 0.209 | 0.244 | 5.3 | +| 100k | `join_3_scan` | 167 | 200 | 43.212 | 50.092 | 14.5 | +| 100k | `recursive_ancestors` | 5 | 200 | 1.162 | 1.247 | 5.3 | +| 1m | `attribute_scan` | 166,666 | 110 | 136.239 | 148.003 | 7.2 | +| 1m | `join_3_selective` | 10 | 200 | 0.204 | 0.247 | 5.0 | +| 1m | `join_3_scan` | 1,667 | 13 | 1170.474 | 1221.751 | 46.3 | +| 1m | `recursive_ancestors` | 6 | 200 | 1.446 | 1.723 | 5.3 | +| 10m | `attribute_scan` | 1,666,666 | 11 | 1366.540 | 1391.023 | 7.4 | +| 10m | `join_3_selective` | 10 | 200 | 0.197 | 0.242 | 5.1 | +| 10m | `join_3_scan` | 16,667 | 5 | 13373.934 | 13422.707 | 61.4 | +| 10m | `recursive_ancestors` | 7 | 200 | 2.057 | 2.804 | 5.6 | + +### Profiles at 1M + +The [profile summary](532-profile-summary.json) validates each child's shape, +row count and timed runs, and reports zero lost samples for all four retained +captures. All use DWARF call graphs and inline-aware reports. The original +499 Hz recursive capture lost 210 samples in three chunks; it was discarded +and repeated at 249 Hz, with zero loss. No envelope timing was repeated or +changed by this profiling adjustment. + +| Shape | Hz | Children | Samples | Identified query samples | `net_asserted_facts` samples | Share of identified query cycles | +|---|---:|---:|---:|---:|---:|---:| +| `attribute_scan` | 499 | 1 | 7,784 | 7,631 | 0 | 0% | +| `join_3_selective` | 499 | 200 | 22,010 | 4,515 | 2 | 0.045% | +| `join_3_scan` | 499 | 1 | 8,280 | 8,155 | 1 | 0.013% | +| `recursive_ancestors` | 249 | 40 | 4,891 | 3,055 | 4 | 0.128% | + +All [seven sampled stacks](532-net-assert-stacks.txt) containing +`net_asserted_facts` reach it through `Snapshot::pending_live`, `RunWalk` and +`flush_run`. Source analysis establishes that their input is empty on these +fixtures: the builder checkpoints before closing, all three fixtures have no +WAL, readers open read-only, and rule magic seeds live in derived relations, +not the pending store. These samples do not represent a second pass over +committed facts. No capture contains `filter_facts_for_query`, +`RecursiveEvaluator` or `StratifiedEvaluator` frames. + +Each child also calls `fixture_shapes` before measuring, which reads the fact +log to construct the queries' timestamp parameters. This setup accounts for +76.2% of sampled cycles in the fast selective capture. The +[summarizer](532-summarize-profiles.py) classifies stacks containing that helper +as setup first, then stacks with `drain`, engine or pending-net-assert frames +as identifiable query work, and the remainder as other. Rust crate +disambiguators are removed only for symbol matching. Cycle percentages sum +the samples' periods; the net-assert percentages above use identifiable query +periods as their denominator. + +These 16 KiB DWARF captures identify 7,323 / 4,133 / 8,150 / 14 query samples +respectively without a `drain` frame: visible engine/pending frames establish +their category. Almost all identified recursive-query samples do reach +`drain`. Separately, 7,320 / 4,331 / 8,149 / 2,982 stacks end at an unknown +outer frame; those counts include chains that already reach `drain` or `main` +and do not measure missing `drain` callers. The summary retains both +diagnostics without inventing ancestry. Unresolved leaf symbols account for 25.7% / 43.3% / 31.3% / 38.4% +of identifiable query cycles respectively. These are corroborating profiles, +not a complete hotspot breakdown or proof of absence by sampling. The static +caller/cfg audit supplies that proof for committed-fact inputs. + +**Outcome:** #532's closing checks are met: all audited v3 query paths bypass +the deleted committed-fact pass, the full envelope completes, and usable +scan/join/rule profiles corroborate the distinction between committed keys +and empty pending walks. Close #532 as superseded by #551; no engine patch +is needed. + +## Reproducing + +On an otherwise idle bench host, check out the measured revision. Copy the +linked [dependency lockfile](531-Cargo.lock) to its root as `Cargo.lock`, and +the [row checker](532-check-rows.rs) to `examples/check_532_rows.rs`. Save the +[profile driver](532-profile.sh) and [summarizer](532-summarize-profiles.py) +outside that checkout and set `profile_driver` and `summary_script` to their +paths. Set `run_dir` to a fresh scratch directory outside the checkout: + +```bash +mkdir -p "$run_dir" +export CARGO_TARGET_DIR="$run_dir/target" +export CARGO_PROFILE_ENVELOPE_DEBUG=2 +export RUSTFLAGS='-Cforce-frame-pointers=yes' +cargo build --profile envelope --example perf_envelope --example check_532_rows --locked +numactl --cpunodebind=1 --membind=1 \ + "$CARGO_TARGET_DIR/envelope/examples/perf_envelope" \ + --scales 100k,1m,10m --budget-secs 15 --cap-secs 60 \ + --dir "$run_dir/fixtures" --json "$run_dir/envelope.json" +"$CARGO_TARGET_DIR/envelope/examples/check_532_rows" \ + "$run_dir/fixtures" "$run_dir/envelope.json" > "$run_dir/row-checks.json" +bash "$profile_driver" "$run_dir" +python3 "$summary_script" "$run_dir" > "$run_dir/profile-summary.json" +``` + +The driver verifies that the 1M fixture has metadata and no nonempty WAL, +records CPU/process snapshots, then captures each shape separately with +`perf record -e cycles:u --call-graph dwarf,16384`, at 499 Hz for scans/joins +and 249 Hz for the recursive shape, with both CPU and memory pinned. The +indices were verified against the pinned `shapes` list: +2 = `attribute_scan`, 4 = `join_3_selective`, 5 = `join_3_scan`, +10 = `recursive_ancestors`. The selective and rule shapes repeat the existing +`__query` child 200 and 40 times respectively, since each child stops at 200 +timed iterations. The other two shapes run one child each. No query source +or benchmark harness is modified. + +It writes `perf report --stdio --header --children --inline` output and +`perf script --inline -F comm,pid,tid,time,event,period,ip,sym,dso` stacks, +demangled with `c++filt -s rust`. Check shape names, row counts, errors/caps, +sample counts and lost samples before drawing conclusions. Keep the reports, +then remove scratch fixtures, builds and raw captures. The dependency lockfile +SHA-256 is `b03965119fd8ce5b5cf3ad3d37fb194ffeae24b6a862a0c85ae8fbcb6833ee77`. + +A clean reproduction has an empty `discarded_captures` summary. The summarizer +adds that diagnostic only when `discarded-recursive/` contains manually +preserved record/report files from a failed earlier capture; the driver does +not create that directory automatically. + +## Deviations from the approved design + +None in scope: this task verifies existing behavior and documents evidence. +It changes no query implementation, API, format, dependency or release. + +Measurement adjustment: the initial recursive recording lost data, so only +that capture was repeated at 249 Hz instead of 499 Hz. Its discarded-run +diagnostics remain in the summary. The stack classification uses identifiable +query frames rather than requiring a complete chain to `drain`, because many +16 KiB captures lack outer callers; the limits are stated above. + +The standalone row checker is compiled as a temporary example against the +pinned library; it is retained under `docs/benchmarks/` and adds no core test +or public API. README, test-coverage counts and release history were +cross-checked and are unchanged. The docs site already documents #551's engine +dispatch; this evidence-only task changes no site behavior or release entry. diff --git a/docs/benchmarks/532-net-assert-stacks.txt b/docs/benchmarks/532-net-assert-stacks.txt new file mode 100644 index 0000000000..cec446c949 --- /dev/null +++ b/docs/benchmarks/532-net-assert-stacks.txt @@ -0,0 +1,162 @@ +All sampled net_asserted_facts stacks; addresses, process IDs and host paths omitted. +Stacks may have unavailable outer callers; source analysis establishes empty pending inputs. + +join_3_selective: period=7226315 cycles + >::with_hasher (inlined) + as core::default::Default>::default (inlined) + >::new (inlined) + minigraf::graph::storage::net_asserted_facts (inlined) + minigraf::graph::storage::flush_run (perf_envelope) + ::run::, alloc::collections::btree::map::Range>::{closure#3}>, ::pending_live::{closure#2}, ::pending_live::{closure#3}> (inlined) + ::pending_live (perf_envelope) + ::next_batch (perf_envelope) + ::next_probe (inlined) + ::next_batch (perf_envelope) + ::pull (inlined) + ::next_rows (perf_envelope) + [unknown] ([unknown]) + +join_3_selective: period=6712710 cycles + , !>>::get_or_init::<::new::KEYS::__rust_std_internal_init_fn> (inlined) + ::new::KEYS::{K#0}::{closure#1} (inlined) + <::new::KEYS::{K#0}::{closure#1} as core::ops::function::FnOnce<(core::option::Option<&mut core::option::Option>>,)>>::call_once (inlined) + >>::try_with::<::new::{closure#0}, std::hash::random::RandomState> (inlined) + >>::with::<::new::{closure#0}, std::hash::random::RandomState> (inlined) + ::new (inlined) + ::default (inlined) + as core::default::Default>::default (inlined) + >::new (inlined) + minigraf::graph::storage::net_asserted_facts (inlined) + minigraf::graph::storage::flush_run (perf_envelope) + ::run::, alloc::collections::btree::map::Range>::{closure#3}>, ::pending_live::{closure#2}, ::pending_live::{closure#3}> (inlined) + ::pending_live (perf_envelope) + ::next_batch (perf_envelope) + ::next_probe (inlined) + ::next_batch (perf_envelope) + ::pull (inlined) + ::next_rows (perf_envelope) + [unknown] ([unknown]) + +join_3_scan: period=6203084 cycles + <*const minigraf::graph::types::Fact>::offset_from_unsigned (inlined) + <*mut minigraf::graph::types::Fact>::offset_from_unsigned (inlined) + , alloc::vec::into_iter::IntoIter>, minigraf::graph::storage::net_asserted_facts::{closure#5}> as alloc::vec::in_place_collect::SpecInPlaceCollect, alloc::vec::into_iter::IntoIter>, minigraf::graph::storage::net_asserted_facts::{closure#5}>>>::collect_in_place (inlined) + alloc::vec::in_place_collect::from_iter_in_place::, alloc::vec::into_iter::IntoIter>, minigraf::graph::storage::net_asserted_facts::{closure#5}>, minigraf::graph::types::Fact> (inlined) + as alloc::vec::spec_from_iter::SpecFromIter, alloc::vec::into_iter::IntoIter>, minigraf::graph::storage::net_asserted_facts::{closure#5}>>>::from_iter (inlined) + as core::iter::traits::collect::FromIterator>::from_iter::, alloc::vec::into_iter::IntoIter>, minigraf::graph::storage::net_asserted_facts::{closure#5}>> (inlined) + , alloc::vec::into_iter::IntoIter>, minigraf::graph::storage::net_asserted_facts::{closure#5}> as core::iter::traits::iterator::Iterator>::collect::> (inlined) + minigraf::graph::storage::net_asserted_facts (inlined) + minigraf::graph::storage::flush_run (perf_envelope) + ::run::, alloc::collections::btree::map::Range>::{closure#3}>, ::pending_live::{closure#2}, ::pending_live::{closure#3}> (inlined) + ::pending_live (perf_envelope) + ::next_batch (perf_envelope) + ::next_probe (inlined) + ::next_batch (perf_envelope) + ::pull (inlined) + ::next_rows (perf_envelope) + [unknown] ([unknown]) + +recursive_ancestors: period=14688751 cycles + ::try_allocate_in (inlined) + ::with_capacity_in (inlined) + >>::with_capacity_in (inlined) + >>::with_capacity_in (inlined) + >>::with_capacity (inlined) + > as alloc::vec::spec_from_iter_nested::SpecFromIterNested, core::iter::adapters::map::Map, minigraf::graph::storage::net_asserted_facts::{closure#0}>>>::from_iter (inlined) + > as alloc::vec::spec_from_iter::SpecFromIter, core::iter::adapters::map::Map, minigraf::graph::storage::net_asserted_facts::{closure#0}>>>::from_iter (inlined) + > as core::iter::traits::collect::FromIterator>>::from_iter::, minigraf::graph::storage::net_asserted_facts::{closure#0}>> (inlined) + , minigraf::graph::storage::net_asserted_facts::{closure#0}> as core::iter::traits::iterator::Iterator>::collect::>> (inlined) + minigraf::graph::storage::net_asserted_facts (inlined) + minigraf::graph::storage::flush_run (perf_envelope) + ::run::, alloc::collections::btree::map::Range>::{closure#3}>, ::pending_live::{closure#2}, ::pending_live::{closure#3}> (inlined) + ::pending_live (perf_envelope) + ::next_batch (perf_envelope) + ::next_probe (inlined) + ::next_batch (perf_envelope) + minigraf::query::engine::recursive::heads (inlined) + minigraf::query::engine::recursive::evaluate (inlined) + minigraf::query::engine::open_rules (inlined) + ::open_rule_query::{closure#5} (perf_envelope) + ::open_rule_query (inlined) + ::open_query (perf_envelope) + ::open (inlined) + ::query_inner (inlined) + ::query (inlined) + perf_envelope::drain (perf_envelope) + perf_envelope::measure_query (inlined) + perf_envelope::main (perf_envelope) + [unknown] ([unknown]) + +recursive_ancestors: period=11371936 cycles + ::wrapping_add (inlined) + ::new::{closure#0} (inlined) + >>::try_with::<::new::{closure#0}, std::hash::random::RandomState> (inlined) + >>::with::<::new::{closure#0}, std::hash::random::RandomState> (inlined) + ::new (inlined) + ::default (inlined) + as core::default::Default>::default (inlined) + >::new (inlined) + minigraf::graph::storage::net_asserted_facts (inlined) + minigraf::graph::storage::flush_run (perf_envelope) + ::run::, alloc::collections::btree::map::Range>::{closure#3}>, ::pending_live::{closure#2}, ::pending_live::{closure#3}> (inlined) + ::pending_live (perf_envelope) + ::next_batch (perf_envelope) + ::next_probe (inlined) + ::next_batch (perf_envelope) + minigraf::query::engine::recursive::heads (inlined) + minigraf::query::engine::recursive::evaluate (inlined) + minigraf::query::engine::open_rules (inlined) + ::open_rule_query::{closure#5} (perf_envelope) + ::open_rule_query (inlined) + ::open_query (perf_envelope) + ::open (inlined) + ::query_inner (inlined) + ::query (inlined) + perf_envelope::drain (perf_envelope) + perf_envelope::measure_query (inlined) + perf_envelope::main (perf_envelope) + [unknown] ([unknown]) + +recursive_ancestors: period=14701204 cycles + minigraf::graph::storage::net_asserted_facts (inlined) + minigraf::graph::storage::flush_run (perf_envelope) + ::run::, alloc::collections::btree::map::Range>::{closure#3}>, ::pending_live::{closure#2}, ::pending_live::{closure#3}> (inlined) + ::pending_live (perf_envelope) + ::next_batch (perf_envelope) + ::next_probe (inlined) + ::next_batch (perf_envelope) + minigraf::query::engine::recursive::heads (inlined) + minigraf::query::engine::recursive::evaluate (inlined) + minigraf::query::engine::open_rules (inlined) + ::open_rule_query::{closure#5} (perf_envelope) + ::open_rule_query (inlined) + ::open_query (perf_envelope) + ::open (inlined) + ::query_inner (inlined) + ::query (inlined) + perf_envelope::drain (perf_envelope) + perf_envelope::measure_query (inlined) + perf_envelope::main (perf_envelope) + [unknown] ([unknown]) + +recursive_ancestors: period=14607095 cycles + minigraf::graph::storage::net_asserted_facts (inlined) + minigraf::graph::storage::flush_run (perf_envelope) + ::run::, alloc::collections::btree::map::Range>::{closure#3}>, ::pending_live::{closure#2}, ::pending_live::{closure#3}> (inlined) + ::pending_live (perf_envelope) + ::next_batch (perf_envelope) + ::next_probe (inlined) + ::next_batch (perf_envelope) + minigraf::query::engine::recursive::heads (inlined) + minigraf::query::engine::recursive::evaluate (inlined) + minigraf::query::engine::open_rules (inlined) + ::open_rule_query::{closure#5} (perf_envelope) + ::open_rule_query (inlined) + ::open_query (perf_envelope) + ::open (inlined) + ::query_inner (inlined) + ::query (inlined) + perf_envelope::drain (perf_envelope) + perf_envelope::measure_query (inlined) + perf_envelope::main (perf_envelope) + [unknown] ([unknown]) diff --git a/docs/benchmarks/532-profile-summary.json b/docs/benchmarks/532-profile-summary.json new file mode 100644 index 0000000000..3c6effa118 --- /dev/null +++ b/docs/benchmarks/532-profile-summary.json @@ -0,0 +1,202 @@ +{ + "revision": "d0ad89c1d6df734afd5d4669ca9139c8f55d7702", + "event": "cycles:u", + "call_graph": "dwarf,16384", + "inline_expansion": true, + "discarded_captures": { + "recursive_ancestors": { + "frequency_hz": 499, + "samples": 9475, + "lost_samples": 210, + "lost_chunks": 3, + "reason": "recorder reported data loss" + } + }, + "profiles": { + "attribute_scan": { + "children": 1, + "rows_per_query": 166666, + "frequency_hz": 499, + "timed_queries": 108, + "samples": 7784, + "lost_samples": 0, + "sample_counts": { + "fixture_setup": 89, + "other": 64, + "query": 7631 + }, + "weighted_cycle_percent": { + "fixture_setup": 0.9652901636016978, + "other": 0.8230725809778963, + "query": 98.2116372554204 + }, + "stack_sample_counts": { + "net_asserted_facts": 0, + "flush_run": 0, + "RunWalk": 0, + "filter_facts_for_query": 0, + "RecursiveEvaluator": 0, + "StratifiedEvaluator": 0, + "minigraf::query::engine::scan": 3109, + "live_keys": 2659, + "live_walk": 2659 + }, + "query_stack_sample_counts": { + "minigraf::query::engine::scan": 3109, + "live_keys": 2658, + "live_walk": 2658 + }, + "unwind_diagnostics": { + "query_without_drain_frame": 7323, + "ending_at_unknown_outer_frame": 7320, + "with_drain_frame": 308 + }, + "net_asserted_facts_percent_of_identified_query_cycles": 0.0, + "unresolved_leaf_percent_of_identified_query_cycles": 25.738693087591027, + "lost_sample_header": [ + "# Total Lost Samples: 0" + ] + }, + "join_3_selective": { + "children": 200, + "rows_per_query": 10, + "frequency_hz": 499, + "timed_queries": 40000, + "samples": 22010, + "lost_samples": 0, + "sample_counts": { + "fixture_setup": 17221, + "query": 4515, + "other": 274 + }, + "weighted_cycle_percent": { + "fixture_setup": 76.20516406713254, + "query": 22.805260669725907, + "other": 0.9895752631415438 + }, + "stack_sample_counts": { + "net_asserted_facts": 2, + "flush_run": 2, + "RunWalk": 6, + "filter_facts_for_query": 0, + "RecursiveEvaluator": 0, + "StratifiedEvaluator": 0, + "minigraf::query::engine::scan": 3679, + "live_keys": 3335, + "live_walk": 3333 + }, + "query_stack_sample_counts": { + "minigraf::query::engine::scan": 3679, + "live_keys": 3335, + "live_walk": 3333, + "RunWalk": 6, + "net_asserted_facts": 2, + "flush_run": 2 + }, + "unwind_diagnostics": { + "query_without_drain_frame": 4133, + "ending_at_unknown_outer_frame": 4331, + "with_drain_frame": 382 + }, + "net_asserted_facts_percent_of_identified_query_cycles": 0.045166696647386276, + "unresolved_leaf_percent_of_identified_query_cycles": 43.25271076412927, + "lost_sample_header": [ + "# Total Lost Samples: 0" + ] + }, + "join_3_scan": { + "children": 1, + "rows_per_query": 1667, + "frequency_hz": 499, + "timed_queries": 13, + "samples": 8280, + "lost_samples": 0, + "sample_counts": { + "fixture_setup": 93, + "query": 8155, + "other": 32 + }, + "weighted_cycle_percent": { + "fixture_setup": 1.05803001403678, + "query": 98.5548209201231, + "other": 0.38714906584010844 + }, + "stack_sample_counts": { + "net_asserted_facts": 1, + "flush_run": 1, + "RunWalk": 1, + "filter_facts_for_query": 0, + "RecursiveEvaluator": 0, + "StratifiedEvaluator": 0, + "minigraf::query::engine::scan": 672, + "live_keys": 607, + "live_walk": 607 + }, + "query_stack_sample_counts": { + "minigraf::query::engine::scan": 672, + "live_keys": 607, + "live_walk": 607, + "net_asserted_facts": 1, + "flush_run": 1, + "RunWalk": 1 + }, + "unwind_diagnostics": { + "query_without_drain_frame": 8150, + "ending_at_unknown_outer_frame": 8149, + "with_drain_frame": 5 + }, + "net_asserted_facts_percent_of_identified_query_cycles": 0.012779856173683005, + "unresolved_leaf_percent_of_identified_query_cycles": 31.343490552003566, + "lost_sample_header": [ + "# Total Lost Samples: 0" + ] + }, + "recursive_ancestors": { + "children": 40, + "rows_per_query": 6, + "frequency_hz": 249, + "timed_queries": 8000, + "samples": 4891, + "lost_samples": 0, + "sample_counts": { + "fixture_setup": 1811, + "query": 3055, + "other": 25 + }, + "weighted_cycle_percent": { + "fixture_setup": 32.261315749751745, + "query": 67.26271789974335, + "other": 0.47596635050491004 + }, + "stack_sample_counts": { + "net_asserted_facts": 4, + "flush_run": 6, + "RunWalk": 13, + "filter_facts_for_query": 0, + "RecursiveEvaluator": 0, + "StratifiedEvaluator": 0, + "minigraf::query::engine::scan": 2149, + "live_keys": 1760, + "live_walk": 1759 + }, + "query_stack_sample_counts": { + "minigraf::query::engine::scan": 2149, + "live_keys": 1760, + "live_walk": 1759, + "RunWalk": 13, + "flush_run": 6, + "net_asserted_facts": 4 + }, + "unwind_diagnostics": { + "with_drain_frame": 3041, + "ending_at_unknown_outer_frame": 2982, + "query_without_drain_frame": 14 + }, + "net_asserted_facts_percent_of_identified_query_cycles": 0.1280860646616853, + "unresolved_leaf_percent_of_identified_query_cycles": 38.449662883753035, + "lost_sample_header": [ + "# Total Lost Samples: 0" + ] + } + } +} diff --git a/docs/benchmarks/532-profile.sh b/docs/benchmarks/532-profile.sh new file mode 100644 index 0000000000..23e4068392 --- /dev/null +++ b/docs/benchmarks/532-profile.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash +set -euo pipefail +bench_run=${1:?usage: 532-profile.sh RUN_DIR} +export bench_run +test -s "$bench_run/fixtures/fixture-v1-1m.json" +test ! -s "$bench_run/fixtures/fixture-v1-1m.graph.wal" +{ + date -u + uptime + ps -eo pid,pcpu,comm --sort=-pcpu | head -15 +} > "$bench_run/load-before-profiles.txt" +for spec in attribute_scan:2:1 join_3_selective:4:200 join_3_scan:5:1 recursive_ancestors:10:40; do + name=${spec%%:*} + rest=${spec#*:} + index=${rest%%:*} + repeats=${rest#*:} + frequency=499 + # The original 499 Hz recursive capture lost samples; 249 Hz was retried. + if [ "$name" = recursive_ancestors ]; then frequency=249; fi + perf record -e cycles:u -F "$frequency" --call-graph dwarf,16384 \ + -o "$bench_run/$name.data" -- \ + numactl --cpunodebind=1 --membind=1 sh -c ' + index=$1 + repeats=$2 + count=0 + while [ "$count" -lt "$repeats" ]; do + "$bench_run/target/envelope/examples/perf_envelope" __query \ + "$bench_run/fixtures/fixture-v1-1m.graph" "$index" 15 60 + count=$((count + 1)) + done + ' profile-children "$index" "$repeats" \ + > "$bench_run/$name-children.jsonl" 2> "$bench_run/$name-record.log" + perf report -i "$bench_run/$name.data" --stdio --header --children --inline \ + 2> "$bench_run/$name-report-errors.txt" | c++filt -s rust > "$bench_run/$name-report.txt" + perf script -i "$bench_run/$name.data" --inline -F comm,pid,tid,time,event,period,ip,sym,dso \ + 2> "$bench_run/$name-script-errors.txt" | c++filt -s rust > "$bench_run/$name-stacks.txt" +done +{ + date -u + uptime + ps -eo pid,pcpu,comm --sort=-pcpu | head -15 +} > "$bench_run/load-after-profiles.txt" diff --git a/docs/benchmarks/532-row-checks.json b/docs/benchmarks/532-row-checks.json new file mode 100644 index 0000000000..4276bd21fd --- /dev/null +++ b/docs/benchmarks/532-row-checks.json @@ -0,0 +1,38 @@ +[ + { + "expected": 167, + "observed": 167, + "scale": "100k", + "shape": "join_3_scan" + }, + { + "expected": 8400, + "observed": 8400, + "scale": "100k", + "shape": "as_of_ts_scan" + }, + { + "expected": 1667, + "observed": 1667, + "scale": "1m", + "shape": "join_3_scan" + }, + { + "expected": 83400, + "observed": 83400, + "scale": "1m", + "shape": "as_of_ts_scan" + }, + { + "expected": 16667, + "observed": 16667, + "scale": "10m", + "shape": "join_3_scan" + }, + { + "expected": 833400, + "observed": 833400, + "scale": "10m", + "shape": "as_of_ts_scan" + } +] diff --git a/docs/benchmarks/532-summarize-profiles.py b/docs/benchmarks/532-summarize-profiles.py new file mode 100644 index 0000000000..59d3cda039 --- /dev/null +++ b/docs/benchmarks/532-summarize-profiles.py @@ -0,0 +1,114 @@ +"""Summarize 532-profile.sh outputs; run this on the bench host.""" +import collections +import json +import pathlib +import re +import sys + +run_dir = pathlib.Path(sys.argv[1]) +revision = 'd0ad89c1d6df734afd5d4669ca9139c8f55d7702' +summary = {'revision': revision, 'event': 'cycles:u', + 'call_graph': 'dwarf,16384', 'inline_expansion': True, + 'discarded_captures': {}, 'profiles': {}} +discarded = run_dir / 'discarded-recursive' +if discarded.exists(): + record = (discarded / 'recursive_ancestors-record.log').read_text() + header = (discarded / 'recursive_ancestors-report.txt').read_text() + summary['discarded_captures']['recursive_ancestors'] = { + 'frequency_hz': int(re.search(r'sample_freq\s*}\s*=\s*(\d+)', header).group(1)), + 'samples': int(re.search(r'\((\d+) samples\)', record).group(1)), + 'lost_samples': int(re.search(r'# Total Lost Samples:\s*(\d+)', header).group(1)), + 'lost_chunks': int(re.search(r'lost (\d+) chunks', record).group(1)), + 'reason': 'recorder reported data loss', + } + +def blocks(path): + block = [] + with path.open() as stream: + for line in stream: + if line.strip(): + block.append(line.rstrip()) + elif block: + yield block + block = [] + if block: + yield block + +for name, repeats, rows in [('attribute_scan', 1, 166666), + ('join_3_selective', 200, 10), + ('join_3_scan', 1, 1667), + ('recursive_ancestors', 40, 6)]: + children = [json.loads(line) for line in (run_dir / f'{name}-children.jsonl').read_text().splitlines()] + assert len(children) == repeats + assert all(c['name'] == name and c['rows'] == rows and c['runs'] >= 5 + and 'error' not in c and 'capped_ms' not in c for c in children) + samples = collections.Counter() + periods = collections.Counter() + symbol_samples = collections.Counter() + symbol_periods = collections.Counter() + query_symbols = collections.Counter() + query_symbol_periods = collections.Counter() + diagnostics = collections.Counter() + total = 0 + for block in blocks(run_dir / f'{name}-stacks.txt'): + header = block[0] + match = re.search(r'(\d+)\s+cycles:u:', header) + if not match: + raise ValueError(f'Unrecognized sample header: {header}') + period = int(match.group(1)) + # rustc v0 symbols may render a crate disambiguator after the crate name. + stack = re.sub(r'\[[0-9a-f]{16}\]', '', '\n'.join(block)) + is_query = any(symbol in stack for symbol in ( + 'perf_envelope::drain', 'minigraf::query::engine', + 'net_asserted_facts', 'minigraf::graph::storage::RunWalk', + 'minigraf::graph::storage::flush_run')) + category = ('fixture_setup' if 'fixture_shapes' in stack else + 'query' if is_query else 'other') + if category == 'query' and 'perf_envelope::drain' not in stack: + diagnostics['query_without_drain_frame'] += 1 + if 'perf_envelope::drain' in stack: + diagnostics['with_drain_frame'] += 1 + if 'ffffffffffffffff [unknown]' in stack: + diagnostics['ending_at_unknown_outer_frame'] += 1 + samples[category] += 1 + periods[category] += period + total += 1 + for symbol in ['net_asserted_facts', 'flush_run', 'RunWalk', + 'filter_facts_for_query', 'RecursiveEvaluator', 'StratifiedEvaluator', + 'minigraf::query::engine::scan', 'live_keys', 'live_walk']: + if symbol in stack: + symbol_samples[symbol] += 1 + symbol_periods[symbol] += period + if category == 'query': + query_symbols[symbol] += 1 + query_symbol_periods[symbol] += period + if category == 'query' and ('[unknown]' in '\n'.join(block[:2])): + symbol_periods['unresolved_query_leaf'] += period + assert total >= 1000 and samples['query'] >= 1000, (name, total, samples) + assert query_symbols['minigraf::query::engine::scan'] > 0 + report_lines = (run_dir / f'{name}-report.txt').read_text().splitlines() + frequency = re.search(r'sample_freq\s*}\s*=\s*(\d+)', '\n'.join(report_lines)) + assert frequency is not None + lost_lines = [line.strip() for line in report_lines if line.startswith('# Total Lost Samples:')] + lost = re.search(r'# Total Lost Samples:\s*(\d+)', '\n'.join(report_lines)) + assert lost is not None and int(lost.group(1)) == 0, (name, lost_lines) + summary['profiles'][name] = { + 'children': repeats, 'rows_per_query': rows, + 'frequency_hz': int(frequency.group(1)), + 'timed_queries': sum(c['runs'] for c in children), 'samples': total, + 'lost_samples': int(lost.group(1)), + 'sample_counts': dict(samples), + 'weighted_cycle_percent': {k: 100 * v / sum(periods.values()) for k, v in periods.items()}, + 'stack_sample_counts': {s: symbol_samples[s] for s in [ + 'net_asserted_facts', 'flush_run', 'RunWalk', 'filter_facts_for_query', + 'RecursiveEvaluator', 'StratifiedEvaluator', + 'minigraf::query::engine::scan', 'live_keys', 'live_walk']}, + 'query_stack_sample_counts': dict(query_symbols), + 'unwind_diagnostics': dict(diagnostics), + 'net_asserted_facts_percent_of_identified_query_cycles': + 100 * query_symbol_periods['net_asserted_facts'] / periods['query'], + 'unresolved_leaf_percent_of_identified_query_cycles': + 100 * symbol_periods['unresolved_query_leaf'] / periods['query'], + 'lost_sample_header': lost_lines, + } +print(json.dumps(summary, indent=2))