← Back to Pull requests

UCS/DATASTRUCT: Find interval tree overlaps in logarithmic time #12367

Closed
unknown closed this pull request without merging on Nov 20, 2026 03:01 UTC
View on GitHub
unknown unknown commented on Nov 17, 2026 12:34 UTC
Author

What?


Make the overlap search in ucs_interval_tree_insert_slow() a single binary-search descent, which also merges overlapping nodes and finds the insertion point. Inserting into an interval tree then costs O(log n) instead of O(n). Also add regression tests.

Why?


Since #11248 the rcache keeps pending invalidations in an interval tree, which it inserts into 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. Workloads that free many non-adjacent buffers while another thread uses the rcache slowed down substantially:
  • RAPIDS (rapidsmpf/libcudf over UCXX) shuffle with many small messages, 2 nodes x 4 GB200, libcudf_streaming_bench_shuffle -C ucxx -n 20000000 -c 4 -p 4 -o 1024 -m async: 3.7-4.5 s per shuffle before #11248, 9.3-9.7 s with it, 3.6-3.9 s with this fix (UCX_RCACHE_ENABLE=n also gives 4.4 s).

  • cudf-polars PDS-H Q9 (SF30K, 4 x 4 GB200): 72-84 s per iteration with #11248, 42-48 s with this fix, which is the v1.20 level (41-48 s).
  • 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. When it reaches a node that overlaps or touches the range, it merges that node into the range and restarts from the root of the rebalanced tree. The NULL link where the descent ends is where the merged range is inserted. The overlap condition is unchanged.

    Tests:

  • random_insert_matches_reference: checks random inserts against a reference set of merged ranges, comparing both the resulting ranges and total_size. This exercises merges that span nodes in both subtrees.

  • many_disjoint_inserts: 2 x 100k disjoint inserts from both ends, then one merge of everything. The inserts run under UCS_TEST_TIME_LIMIT(10). They take about 50 ms with the fix. Without it they take about 70 s, so the test fails when performance checks are enabled.
  • Diff: 269 lines (+201 / -68) across 3 files Reviewer: pentschev Review duration: 3747m
    All Vouch review confidence checks passed
    Residual risk 0.16 = 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 · 269 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.335
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #12367"
    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.4% (MEDIUM) · Higher = larger blast radius
    39.4%
    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.6% · Safe to merge
    15.6%
    Repository