← Back to Pull requests

Fix quadratic float parsing in next_bytes_is_float #608

Closed
unknown closed this pull request without merging on Jul 16, 2026 09:46 UTC
View on GitHub
unknown unknown commented on Jul 15, 2026 15:03 UTC
Author

Fixes #607.

Problem

Parser::next_bytes_is_float searches the entire remaining input for "..", but clamps the result to the current float-char run:

let raw_float_len = self.next_chars_while_from_len(skip, is_float_char);
let valid_float_len = self.src()[skip..]
    .find("..")                              // scans to EOF
    .map(|i| i.min(raw_float_len))
    .map_or(raw_float_len, |i| i.min(raw_float_len));

Since the result is .min(raw_float_len) anyway, every byte scanned past raw_float_len is wasted. In a document with no ".." in it — the common case — find scans to EOF for every number, making self-describing deserialization (ron::Value / deserialize_any) O(numbers × input_size).

This regressed in v0.12.2 with #602. Same benchmark, only the version differs (--release):

| floats | v0.12.1 | v0.12.2 | slowdown |
|--------|---------|---------|----------|
| 16 000 | 3.2 ms | 335 ms | 105× |
| 32 000 | 6.4 ms | 1 397 ms | 218× |
| 64 000 | 12.2 ms (×1.90) | 5 645 ms (×4.04) | 462× |

Fix

Bound the search to the float-char run — the form any_number already uses a few lines above:

let valid_float_len = self.src()[skip..][..raw_float_len]
    .find("..")
    .map_or(raw_float_len, |i| i.min(raw_float_len));

Behaviour-preserving:

  • A match at index >= raw_float_len was already clamped to raw_float_len, so not finding it changes nothing.

  • A ".." cannot straddle the end of the run: that would require src[raw_float_len] == '.', but '.' is a float char (is_float_char) and would have been part of the run.
  • The now-redundant .map(|i| i.min(raw_float_len)) before .map_or(...) is dropped (map_or already re-applies the same min).

    Result: linear again, 64k floats 5 645 ms → 27 ms (207×).

    Tests

  • All 453 existing tests pass, including the seven range tests from #602.

  • Adds tests/607_quadratic_float_parsing.rs, which asserts on scaling rather than absolute time so it stays meaningful on slow or noisy CI: the ratio is ~2 when linear, ~4 when quadratic, and the threshold (3.0) sits far from both. It bails out if the baseline is too small to measure.
  • I verified the test genuinely catches the bug: on the unfixed parser it fails with ratio 3.90, and it passes on the fixed one.

    Diff: 289 lines (+216 / -73) across 3 files Reviewer: juntyr Review duration: 1122m
    All Vouch review confidence checks passed
    Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 289 lines diff across 3 files
    0.40
    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.339
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #608"
    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.8% (MEDIUM) · Higher = larger blast radius
    39.8%
    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.7% · Safe to merge
    15.7%
    Repository