Latest Results
Optimize version parsing for common `\d.\d.\d` cases (#20118)
## Summary
Version strings in the common `x.y.z` form currently pass through the
generic numeric fast parser, including its per-byte loop and segment
bookkeeping.
This recognizes the exact five-byte form up front, validates the three
ASCII digits, and constructs the existing packed representation
directly. The packed-value construction is shared with the generic
numeric fast path, while every other input continues through the
existing parser so normalization and error behavior remain unchanged.
The regression coverage enumerates all 1,000 single-digit
three-component versions and checks representative non-digit inputs that
must retain the existing fallback behavior.
## Performance
| Input | Original loop | This PR | Change |
| --- | ---: | ---: | ---: |
| `1.2.3` | 9.82 ns | 5.03 ns | 1.95× faster |
| `1.2` | 7.86 ns | 8.29 ns | 5% slower |
| `1.23.4` | 11.59 ns | 11.66 ns | Flat |
| `1.2.3rc1` | 8.74 ns | 10.05 ns | 15% slower |
The optimized single-digit `x.y.z` shape accounts for 24,000 of 47,641
lockfile version occurrences, or 50.4%. Its improvement should therefore
dominate the smaller regressions on fallback inputs.
We also tried unrolling the common six-byte shapes (`1.23.4`, `12.3.4`,
and `1.2.34`), but the added code size made every measured case slower,
so this PR intentionally leaves them on the generic path. Latest Branches
-11%
charlie/prerelease-admission-ranges 0%
0%
charlie/optimize-version-parse-fastpath © 2026 CodSpeed Technology