UCS/DATASTRUCT: Find interval tree overlaps in logarithmic time - v1.23.x #12491
All Vouch review confidence checks passed
Residual risk 0.24 = Change Risk (0.45) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.45 · 432 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 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.363
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #12491"
general
weight: 0.35
tvegas1
What?
Backport of #12367 to v1.23.x, ported to the v1.23.x interval tree.
ucs_interval_tree_insert_slow()now finds overlaps in a single binary-search descent, which also merges overlapping nodes and finds the insertion point. An insert then costs O(log n) instead of O(n). This also adds the regression tests from #12367.Why?
Since #11248 (in v1.23.0) the rcache keeps pending invalidations in an interval tree. It inserts into that tree from memory unmap/free events, under its spinlock. The overlap search visited the whole left subtree of every node, so each insert was linear in the number of pending ranges and a series of inserts was quadratic.
Measured on GB200, with v1.23.x and the other backports for v1.23.x (#11062, #12333) applied, with and without this change:
-o 1024): 9.1 s without, 3.90 s with this change (v1.20.1: 3.90 s, plain v1.23.x: 17.5 s).These v1.23.x runs used an earlier port of the same descent: it kept the old helpers and only made
ucs_interval_tree_find_overlap()follow one path. That port has the same O(log n) cost.On master, #12367 measured 9.3-9.7 s -> 3.6-3.9 s for the shuffle and 72-84 s -> 42-48 s for Q9.
How?
The tree keeps its nodes disjoint and non-adjacent, because inserts merge them. So if the range ends before a node with a gap, only the left subtree can overlap it, and if it starts after the node with a gap, only the right subtree can.
range.end + 1 < node->start, right ifnode->end + 1 < range.start.Tests:
random_insert_matches_referencechecks random inserts against a reference set of merged ranges. It compares both the resulting ranges andtotal_size, and checks the RB invariant.many_disjoint_insertsdoes 2 x 100k disjoint inserts from both ends, then one insert that merges everything. The inserts run underUCS_TEST_TIME_LIMIT(10).Backport notes
v1.23.x does not have #11944, which moved the interval tree onto the generic
ucs_rbtree. On v1.23.x the tree has its own node links (ucs_interval_node_t::left/right/parent), recursive remove/insert helpers, and noucs_rbtree_insert_at(). So the master change does not apply, and this is a port of the same algorithm:tree->rootanducs_interval_node_t::left/rightinstead ofucs_rbtree_node_t.ucs_interval_tree_remove_node(tree, &tree->root, node).node->parent = parent; *link = node;and rebalanced with the existingucs_interval_tree_insert_fixup(), instead ofucs_rbtree_insert_at().ucs_interval_tree_find_overlap()anducs_interval_tree_remove_overlapping()are removed, and so isucs_interval_tree_insert_node(), which is no longer used.check_rb_invariant(), the v1.23.x name forcheck_invariants().