Skip to content

perf: bound long fractional parsing work - #26

Merged
tisonkun merged 2 commits into
mainfrom
codex/improve-parsing
Aug 25, 2026
Merged

perf: bound long fractional parsing work#26
tisonkun merged 2 commits into
mainfrom
codex/improve-parsing

Conversation

@tisonkun

@tisonkun tisonkun commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Summary

  • apply the finite rounding-boundary insight from Russ Cox's floating-point formatting series to byte-size parsing
  • bound exact half-ceil arithmetic to the fractional prefix that can affect the result while still validating every input byte
  • inline the common FromStr parsing path
  • add exact-boundary, malformed-long-input, cross-unit property, and excess-precision benchmark coverage

These results compare origin/main at 7df774f directly with the latest PR head at a3dde4d; they do not compare against an earlier PR commit. Values are the median of seven alternating local Divan runs per revision, with 500 samples of 4,096 iterations per run. The two new benchmark definitions were temporarily applied to main so both revisions used identical inputs; lower is better.

Benchmark main (7df774f) PR (a3dde4d) Change
plain 4.306 ns 3.091 ns -28.2%
decimal-unit 4.754 ns 3.548 ns -25.4%
binary-unit 4.499 ns 3.035 ns -32.5%
fraction 5.724 ns 4.540 ns -20.7%
small-fraction 6.463 ns 5.293 ns -18.1%
grouped 9.732 ns 9.306 ns -4.4%
u64-max 18.22 ns 18.20 ns -0.1%
malformed 3.533 ns 2.292 ns -35.1%
high-precision-decimal 17.65 ns 16.77 ns -5.0%
high-precision-binary 61.13 ns 59.69 ns -2.4%
excess-precision-decimal 163.2 ns 66.98 ns -59.0%
excess-precision-binary 213.0 ns 129.3 ns -39.3%

Across the 10 pre-existing cases, the unweighted geometric-mean latency is 18.1% lower, while the sum of their medians is 7.5% lower. Neither aggregate is a production-workload average because the benchmark cases have no traffic weights.

A main plus inline-only control reproduced the ordinary-input improvements, so those gains come primarily from removing the cross-crate call boundary. The finite-prefix algorithm itself affects only inputs longer than 61 bytes; the existing high-precision inputs do not exercise that branch.

Validated with cargo x lint --fix, cargo x test, and the Rust 1.85 MSRV test suite.

@tisonkun
tisonkun merged commit 9200fbe into main Aug 25, 2026
16 checks passed
@tisonkun
tisonkun deleted the codex/improve-parsing branch August 25, 2026 01:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant