← Back to Pull requests

Start list and tuple index searches at the requested offset #1270

Closed
unknown closed this pull request without merging on Nov 10, 2026 16:20 UTC
View on GitHub
unknown unknown commented on Nov 07, 2026 11:56 UTC
Author

list.index(value, start, end) and tuple.index(...) currently advance their lending iterators from zero, cloning and dropping excluded prefix values before searching the requested window. Initialize the existing iterator position from the normalized start instead.

Keep the existing bounds-coercion order, mutation-safe list reads, comparison path, recursion guard and native timeout polling. Comments explain why excluded entries need no equality calls or reference-count traffic. Tests cover huge/negative bounds, bound coercions that mutate the list, equality callbacks that clear it, empty windows, shared children and callback-driven timeouts.

Microbenchmarks were measured on macOS 27 arm64 with Rust 1.99.0 release builds (fat LTO, one codegen unit), clean main 5bcc54cd versus 2d8790f4. Both binaries were built in the same directory and frozen before timing. Flying Circus ran 40 randomized samples per runtime/mode, serially, with 10 repeated-mode warmups and no builds or tests running alongside measurements. These repeated-worker medians include compilation, setup and execution of the full script, excluding process startup. Scripts were validated with CPython 3.14.2; every measured request checked its assertions and expected output. Benchmark scripts are kept local and are not part of this PR; input sizes and operation counts are listed below.

| Microbenchmark | Main | Candidate | Time change |
| --- | ---: | ---: | ---: |
| 1,000 tail-only searches of a 4,096-item list | 21.4779 ms | 0.2497 ms | -98.84% (86.0x faster) |
| 1,000 tail-only searches of a 4,096-item tuple | 22.5905 ms | 0.2272 ms | -98.99% (99.4x faster) |
| 100 full-range list searches, integer items | 8.5458 ms | 8.4614 ms | -0.99% |
| 200 full-range list searches, heap-string items | 5.5771 ms | 5.6073 ms | +0.54% |

The full-range controls fall below the configured change threshold in repeated mode. The large gains come from eliminating the excluded prefix; they describe these offset-heavy workloads.

The harness used protocol 7 transport compatibility. Timing flags were --diff --samples 40 --warmups 10 --startup-samples 3 --memory-samples 0 --threshold 1 --absolute-threshold-ms 0.01 -x 1, with each script passed using --benchmark and baseline/candidate passed using -r.

Local validation passed: all 1,492 Monty/CPython fixture checks, all 142 reference-count fixture checks, 95 Rust tests across collections, container mutation, dump compatibility, resource limits and the new callback-timeout test, Clippy with warnings denied, Ruff, formatting and import checks. Rust tests and fixtures used memory-model-checks; the reference-count pass also used ref-count-return.

<!-- This is an auto-generated description by cubic. -->
---

Summary by cubic


Starts list.index(value, start, end) and tuple.index(...) searches at the normalized start offset instead of cloning and dropping the excluded prefix entries from zero, which dominated the cost when the needle sat near the end. Also checks the native timeout budget before the search so nested short offset searches can't outrun an expired limit.

  • Excluded prefix entries no longer incur equality calls or reference-count traffic; bounds coercion order, mutation-safe reads, equality callbacks, and the recursion guard behave as before.

  • Adds fixtures and tests covering bounds that mutate the list, equality callbacks that clear it, empty windows, shared children, and callback-driven and nested-search timeouts.

  • Benchmarks: 1,000 tail-only searches of a 4,096-item list run ~86x faster (21.48 ms → 0.25 ms), while full-range searches change by about 1%.
  • <sup>Written for commit 4b0b7aef7f139bea3e50884b5e42169680b9d51f. Summary will update on new commits.</sup>

    <a href="https://cubic.dev/pr/pydantic/monty/pull/1270?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a>

    <!-- End of auto-generated description by cubic. -->

    Diff: 535 lines (+401 / -134) across 6 files Reviewer: jaheba Review duration: 4583m
    All Vouch review confidence checks passed
    Residual risk 0.19 = Change Risk (0.48) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.48 · 535 lines diff across 6 files
    0.48
    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.376
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #1270"
    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: 47.9% (MEDIUM) · Higher = larger blast radius
    47.9%
    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: 18.9% · Safe to merge
    18.9%
    Repository