optimize single-pass f32 parsing#227
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #227 +/- ##
==========================================
+ Coverage 71.08% 71.16% +0.07%
==========================================
Files 42 42
Lines 9744 9762 +18
==========================================
+ Hits 6927 6947 +20
+ Misses 2817 2815 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR updates f32 deserialization to avoid the previous f64-first parsing path (which could mis-round tie-boundary decimals), by introducing and wiring in a dedicated single-pass f32 parser in sonic-number.
Changes:
- Add
sonic_number::parse_float32and shared generic float-parsing helpers forf32. - Switch
Deserializer::deserialize_f32to use the new single-passf32parser (removing the raw-string fallback parse). - Add regression tests for the tie-boundary precision case and direct
parse_float32unit tests.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/serde/mod.rs |
Adds a regression test covering the precision edge case and -0 handling for f32 deserialization. |
src/serde/de.rs |
Replaces the prior f64→f32 + fallback parse approach with a dedicated single-pass f32 parse call. |
src/parser.rs |
Adds a Parser::parse_float32 wrapper that advances the reader index appropriately and maps number errors into parser errors. |
sonic-number/src/lib.rs |
Implements parse_float32, introduces generic float helpers, and adds unit tests for parse_float32. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 253acbad4f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Summary
f32parser insonic-numberDeserializer::deserialize_f32FloatMustBeFinitef32literal target, curated seeds, and CI fuzz-time normalizationBackground
The previous
f32deserialization path first parsed the number asf64and then converted it back tof32. For tie-boundary inputs such as17005001.000000000000130, that can produce an off-by-one ULP result.Changes
This updates
f32parsing to stay on a single pass, avoids the extra string reparse fallback, and preserves the expectedf32rounding behavior for affected cases.On top of the parser change, this PR also strengthens regression coverage around
f32parsing:3.4028236e38and1e39fuzz_f32_literaltarget with curated corpus seeds for rounding and overflow boundariesFUZZ_TIMEin CI so values like3mare passed to libFuzzer as seconds instead of effectively running for only a few secondsValidation
cargo test test_deserialize_f32_single_pass_precisioncargo test --manifest-path sonic-number/Cargo.toml test_parse_float32cargo test --manifest-path fuzz/Cargo.toml