← Back to Pull requests

tapdb: fetch mssmt children without walking the subtree #2320

Closed
unknown closed this pull request without merging on Sep 29, 2026 16:22 UTC
View on GitHub
unknown unknown commented on Sep 29, 2026 09:44 UTC
Author

(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.

BenchmarkTreeMerkleProof, before -> after:

  SQLite      1k leaves    10.4ms -> 0.36ms
             10k leaves     128ms -> 0.42ms
            100k leaves    1638ms -> 0.56ms
  Postgres    1k leaves     569ms -> 1.76ms
             10k leaves    71.5ms -> 2.43ms
            100k leaves   (>10min) -> 2.98ms

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.

Diff: 251 lines (+188 / -63) across 3 files Reviewer: darioAnongba Review duration: 397m
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
0.39
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
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
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 60.5% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 39% (MEDIUM) · Higher = larger blast radius
39%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 60.5% · Lower = rushed or shallow review
60.5%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 15.4% · Safe to merge
15.4%