Skip to content

Deserialize requirement sources in one pass - #2904

Draft
ww-oai wants to merge 5 commits into
mainfrom
codex/deserialize-requirement-source
Draft

ww-oai wants to merge 5 commits into
mainfrom
codex/deserialize-requirement-source

Conversation

@ww-oai

@ww-oai ww-oai commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Read the requirement-source map once. Serde buffers each recognized field independently and skips unknown fields. The first valid source wins in the existing precedence order. A duplicate or type mismatch rules out only the variants that need that field. Errors reading a recognized field, including invalid Unicode and excessive nesting, propagate.

Benchmarks

Release builds of the merge base (4053abea3) and PR head (a1fa03a5d) on Linux x86-64 with Rust 1.99.0. Base and head times are means from the first pass. Each change in elapsed time has a paired 95% confidence interval.

In-memory TOML parse Base Head Time change [95% CI] Confirmation [95% CI]
HTTPX metadata, 12 registry requirements 15.78 µs 11.37 µs −27.95% [−28.16%, −27.73%] −27.60% [−28.11%, −27.10%]
Git metadata, 1 requirement 3.281 µs 3.288 µs +0.21% [−0.005%, +0.42%] +0.16% [−0.36%, +0.63%]
Direct URL/Git lock, 3 packages 17.73 µs 17.88 µs +0.84% [−0.39%, +2.89%] −0.23% [−0.73%, +0.29%]
HTTPX lock, 28 packages 326.40 µs 317.96 µs −2.59% [−3.22%, −1.96%] −2.03% [−2.43%, −1.60%]
uv lock, 96 packages 1.049 ms 1.035 ms −1.36% [−1.93%, −0.73%] −1.22% [−1.67%, −0.79%]
Pyx workspace lock, 226 packages 2.258 ms 2.133 ms −5.56% [−6.03%, −5.13%] −5.20% [−5.83%, −4.41%]

Among the complete lockfiles, the largest reduction was on the Pyx workspace, which has 564 package-metadata requirements. Neither the early-match Git requirement nor the small mixed URL/Git lock showed a conclusive change in either pass.

Lockfile inputs and timing method

The metadata cases deserialize a TOML requires-dist array into Vec<Requirement>, including Serde’s flattened source. The HTTPX input uses its 12 registry requirements with names, specifiers, and markers. The single Git input uses the marked, revision-pinned requirement from the three-package mixed lock. HTTPX snapshot · Git fixture

Each complete file goes through Lock::from_toml. All four used the canonical parser and round-tripped byte-for-byte on both revisions. The Pyx snapshot redacts aiohttp’s patch version. The input restores 3.14.1 using the matching sdist URL and hash in the Black snapshot. uv lockfile · Pyx snapshot · Black snapshot

Each of two independently seeded passes used one pinned CPU and 120 randomized blocks per input. Each block timed the head and two baseline executions in balanced order. The timer covered parsing and dropping the value after warmup. File I/O, process startup, and output verification were outside the timer. Intervals use 10,000 paired bootstrap resamples. The Git baseline-against-itself control measured +0.50% in the first pass and −0.04% in the second.

Direct JSON parsing, CLI timings, and binary size
Case Base Head Time change [95% CI] Confirmation [95% CI]
32 registry sources 31.95 µs 16.06 µs −49.73% [−50.02%, −49.39%] −53.85% [−54.17%, −53.51%]
32 Git sources 40.93 µs 40.65 µs −0.67% [−1.20%, −0.10%] −0.53% [−1.26%, +0.55%]
32 directory sources 24.61 µs 16.00 µs −34.99% [−35.31%, −34.63%] −35.43% [−35.67%, −35.19%]
uv --help 4.37 ms 4.39 ms +0.51% [−0.26%, +1.31%] +0.41% [−0.02%, +0.82%]
Offline Trio fixture 8.95 ms 8.99 ms +0.44% [−0.24%, +1.16%] +0.66% [−0.21%, +1.54%]

The stripped uv executable shrank by 7,232 bytes, from 43,189,792 to 43,182,560. uvx (318,392 bytes) and uv-build (2,955,832 bytes) were byte-identical.

These cases used two independently seeded passes on one pinned CPU with two baseline executions and one head execution per randomized block. Each JSON case used 240 blocks through RequirementSource. Each CLI case used 600 blocks. Intervals use 4,000 paired bootstrap resamples. The uv --help baseline-against-itself controls were −0.13% and +0.52%, with both intervals spanning zero.

The offline resolver used the repository’s Trio input and metadata-only wheels reconstructed from the 38 pins and dependency edges in test/requirements/compiled/trio.txt. Both binaries produced the same 38 pins and identical help text. Both revisions used the same checkout path and locked dependencies. uv and uvx used the release profile with self-update and no PGO. uv-build used the minimal-size profile with LLD identical-code folding.

Verification

All 68 uv-distribution-types library tests, package Clippy, and workspace formatting passed. The GitHub benchmark jobs uploaded results for this head. CPU simulation · Wall time

@ww-oai ww-oai added the test:benchmarks Enable simulated and walltime benchmarks for a pull request label Oct 20, 2026 — with ChatGPT Codex Connector
@ww-oai
ww-oai force-pushed the codex/deserialize-requirement-source branch from 2109b34 to 03d90fd Compare October 20, 2026 23:00
@astral-automations-bot astral-automations-bot Bot added internal A refactor or improvement that is not user-facing performance labels Oct 20, 2026
@ww-oai
ww-oai deployed to automations October 20, 2026 23:06 — with GitHub Actions Active
@ww-oai
ww-oai deployed to automations October 20, 2026 23:10 — with GitHub Actions Active
@codspeed

codspeed Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by 47.45%

1 warning

⚠️ 9 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

⚡ 10 improved benchmarks
✅ 81 untouched benchmarks
⏩ 65 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
⚡ CPU Simulation finish_none[4096] 173.8 ms 44 ms ×3.9
⚡ CPU Simulation finish_none[65536] 104.4 ms 38.9 ms ×2.7
⚡ CPU Simulation finish_blake2b[4096] 602.5 ms 432.2 ms +39.39%
⚡ CPU Simulation finish_sha512[4096] 795 ms 632.9 ms +25.61%
⚡ CPU Simulation finish_sha384[4096] 795 ms 632.9 ms +25.61%
⚡ CPU Simulation finish_sha256[4096] 893 ms 733.7 ms +21.71%
⚡ CPU Simulation finish_blake2b[65536] 514.2 ms 426.6 ms +20.53%
⚡ CPU Simulation finish_sha384[65536] 708.8 ms 626.8 ms +13.08%
⚡ CPU Simulation finish_sha512[65536] 708.8 ms 626.9 ms +13.08%
⚡ CPU Simulation finish_sha256[65536] 808.2 ms 728 ms +11.02%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing codex/deserialize-requirement-source (a1fa03a) with main (4b46af0)2

Open in CodSpeed

Footnotes

  1. 65 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

  2. No successful run was found on main (d2152bc) during the generation of this report, so 4b46af0 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@ww-oai
ww-oai deployed to automations October 21, 2026 00:41 — with GitHub Actions Active
Comment on lines +977 to +982
impl<'de> Deserialize<'de> for RequirementSourceWire {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
deserializer.deserialize_any(SourceVisitor)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] Measure the benefit on flattened lockfile requirements

This replaces a derive with a manually maintained field list, duplicate tracking, and variant precedence, but the supplied timings are head-only JSON measurements. The lockfile consumer deserializes Requirement through #[serde(flatten)], which already buffers fields, while SourceField<T> retains per-field untagged buffering. Direct-source timings therefore do not establish the benefit on that path; the saved CodSpeed report covers unrelated hash-reader benchmarks. Please complete matched merge-base/head measurements using representative flattened TOML requirements or lockfile reads, including variability and early-match Git sources, to justify this additional maintenance cost.

This branch was successfully deployed

1 active (outdated) deployment
automations — daaf1f7c Deployed Oct 21, 2026 by ww-oai via review-code-quality / code quality review #11210
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal A refactor or improvement that is not user-facing performance test:benchmarks Enable simulated and walltime benchmarks for a pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant