Fix quadratic float parsing in next_bytes_is_float #608
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 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.339
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #608"
general
weight: 0.35
juntyr
Fixes #607.
Problem
Parser::next_bytes_is_floatsearches the entire remaining input for"..", but clamps the result to the current float-char run:Since the result is
.min(raw_float_len)anyway, every byte scanned pastraw_float_lenis wasted. In a document with no".."in it — the common case —findscans 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_numberalready uses a few lines above:Behaviour-preserving:
>= raw_float_lenwas already clamped toraw_float_len, so not finding it changes nothing.".."cannot straddle the end of the run: that would requiresrc[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_oralready re-applies the samemin).Result: linear again, 64k floats 5 645 ms → 27 ms (207×).
Tests
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.