tapdb: fetch mssmt children without walking the subtree #2320
All Vouch review confidence checks passed
Residual risk 0.15 = Change Risk (0.39) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.39 · 251 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.331
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #2320"
general
weight: 0.35
darioAnongba
(N.b., this is an opportunistic fix I generated w/Opus 5.5 whilst digging into some universe server logs. We usually eat a massive spike of latency for some hours after a restart or upgrade due to dropping the cache; this should mitigate that dramatically. Opus's summary follows.)
FetchChildren was a recursive CTE whose depth bound lived in the outer SELECT rather than in the recursive term. Neither SQLite nor Postgres pushes such a filter into the recursion, so every call materialised the entire subtree beneath the node, only to discard all but a handful of rows. GetChildren only ever uses the node and its two direct children.
CompactedTree walks call GetChildren once per level from the root, so each MerkleProof or Insert read on the order of the whole tree. On a 100k-leaf tree in Postgres with planner statistics, one call at the root produced 244,653 rows to return 7, spilled to temp files and took 944ms; on a fresh table without statistics a single call ran for more than ten minutes.
Replace the CTE with a join of the node against its own hash and its child hashes: three primary key lookups on both backends, taking 0.04ms for the same Postgres call. The rows no longer arrive parent first, so GetChildren now finds the node by its hash rather than by position.
The Postgres "before" figures were taken on fresh tables, where the old query's cost also depended on whether autoanalyze had run yet.
Writes walk the tree the same way. A single Insert into a populated tree drops from 1767ms to 8.9ms at 100k leaves on SQLite, and from 634ms to 7.0ms at 10k leaves on Postgres, where BenchmarkMultiverseLeafIngestSingle drops from 244ms to 18ms.