Commit 9adb63e
authored
Reduce VersionSpecifiers parsing allocations (#20105)
## Summary
`VersionSpecifiers::from_str` currently collects every parsed constraint
into a growable `Vec`, sorts it, and converts it to a boxed slice. Most
`requires-python` values contain a single clause, so parsing a value
like `>=3.8` pays for temporary spare capacity and sorting before
shrinking the allocation.
This constructs empty and single-clause collections directly, and counts
separators once so multi-clause inputs reserve their exact final size.
Parsing and error behavior remain unchanged.
In profiling builds, the single-clause case improves from about 129 ns
to 74 ns (-43%). Exact sizing improves a two-clause input by about 10%
and a five-clause input by about 9%. A CodSpeed benchmark covers all
three shapes.
The `uv-pep440` and `uv-pypi-types` suites pass, along with formatting
and strict Clippy checks for `uv-pep440` and the new benchmark.1 parent 5c0c508 commit 9adb63e
2 files changed
Lines changed: 35 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
308 | 309 | | |
309 | 310 | | |
310 | 311 | | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
311 | 325 | | |
312 | 326 | | |
313 | 327 | | |
| |||
328 | 342 | | |
329 | 343 | | |
330 | 344 | | |
331 | | - | |
| 345 | + | |
| 346 | + | |
332 | 347 | | |
333 | 348 | | |
334 | 349 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
156 | 156 | | |
157 | 157 | | |
158 | 158 | | |
159 | | - | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
160 | 176 | | |
161 | 177 | | |
162 | 178 | | |
| |||
937 | 953 | | |
938 | 954 | | |
939 | 955 | | |
| 956 | + | |
940 | 957 | | |
941 | | - | |
942 | | - | |
943 | | - | |
944 | | - | |
| 958 | + | |
945 | 959 | | |
946 | 960 | | |
947 | 961 | | |
| |||
0 commit comments