← Back to Pull requests

UCS/DATASTRUCT: Find interval tree overlaps in logarithmic time - v1.23.x #12491

Open
unknown opened this pull request with 432 lines diff across 5 files
View on GitHub
unknown unknown commented on Nov 26, 2026 21:53 UTC
Author

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:

  • rapidsmpf shuffle benchmark, 2 nodes, many small messages (-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).

  • cudf-polars PDS-H Q9, SF30K, 4 x NVL4 GB200: 77.1 s per iteration (then OOM) without this change, 49.1 / 42.1 s with it (v1.20.1: 48.8 / 41.7 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.
  • The insert descends along one path from the root: left if range.end + 1 < node->start, right if node->end + 1 < range.start.

  • When it reaches a node which overlaps or touches the range, it merges that node into the range, removes it, and restarts from the root of the rebalanced tree. The overlap condition is unchanged.

  • The NULL link where the descent ends is where the merged range is inserted. The new node is attached there and rebalanced.
  • Tests:

  • random_insert_matches_reference checks random inserts against a reference set of merged ranges. It compares both the resulting ranges and total_size, and checks the RB invariant.

  • many_disjoint_inserts does 2 x 100k disjoint inserts from both ends, then one insert that merges everything. The inserts run under UCS_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 no ucs_rbtree_insert_at(). So the master change does not apply, and this is a port of the same algorithm:
  • The descent walks tree->root and ucs_interval_node_t::left/right instead of ucs_rbtree_node_t.

  • A merged node is removed with the existing ucs_interval_tree_remove_node(tree, &tree->root, node).

  • The new node is attached with node->parent = parent; *link = node; and rebalanced with the existing ucs_interval_tree_insert_fixup(), instead of ucs_rbtree_insert_at().

  • As on master, ucs_interval_tree_find_overlap() and ucs_interval_tree_remove_overlapping() are removed, and so is ucs_interval_tree_insert_node(), which is no longer used.

  • The two new tests are taken as is, except that they use check_rb_invariant(), the v1.23.x name for check_invariants().
  • Diff: 432 lines (+324 / -108) across 5 files Reviewer: tvegas1 Review duration: 1323m
    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
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    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.363
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #12491"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% 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: 45.2% (MEDIUM) · Higher = larger blast radius
    45.2%
    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: 46.7% · Lower = rushed or shallow review
    46.7%
    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: 24.1% · Safe to merge
    24.1%
    Repository