Skip to content

Parse PyPI Simple API JSON responses directly - #21040

Closed
charliermarsh wants to merge 2 commits into
mainfrom
charlie/simple-api-json-parser
Closed

charliermarsh wants to merge 2 commits into
mainfrom
charlie/simple-api-json-parser

Conversation

@charliermarsh

Copy link
Copy Markdown
Member

Summary

PyPI Simple API project responses currently deserialize through Serde into an intermediate Vec<PypiFileWire> before converting each entry into PypiFile. For packages with thousands of distributions, that extra pass, generic JSON dispatch, and temporary string allocations make index decoding unnecessarily expensive.

Parse ordinary unescaped responses directly into PypiFile, borrowing JSON strings while parsing, retaining the existing requires-python interner, and recognizing the common single-SHA-256 hash representation. Continue parsing upload timestamps with Jiff. Inputs with escaped strings, unsupported representations, malformed syntax, or invalid UTF-8 fall back to the existing serde_json implementation, preserving compatibility and diagnostics. Pyx, MessagePack, HTML, and root-index responses are unchanged.

The parser matches Serde across 558 differential cases, including malformed inputs, metadata aliases, duplicate fields, ignored values, project statuses, timestamp edge cases, and shared requires-python allocations; the uv-pypi-types and registry-client tests, Clippy, and a mock-index installation also pass.

Benchmarks

Medians from 101 warmed, randomized, paired measurements against captured PyPI Simple API responses. These measurements cover JSON parsing only, not complete uv command execution.

Input Files serde_json Direct Result
NumPy, 2.89 MB 4,100 2.744 ms 1.594 ms 1.72× faster (41.9%)
Ruff, 4.80 MB 7,026 4.672 ms 2.563 ms 1.82× faster (45.1%)

@codspeed

codspeed Bot commented Aug 10, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 25 untouched benchmarks
⏩ 6 skipped benchmarks1


Comparing charlie/simple-api-json-parser (67391e8) with main (a50af60)

Open in CodSpeed

Footnotes

  1. 6 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. ↩

@codspeed

codspeed Bot commented Aug 10, 2026

Copy link
Copy Markdown

Unable to generate the flame graphs

The performance report has correctly been generated, but there was an internal error while generating the flame graphs for this run. We're working on fixing the issue. Feel free to contact us on Discord or at [email protected] if the issue persists.

@charliermarsh

Copy link
Copy Markdown
Member Author

I had Codex do this but I think in practice it doesn't really matter:

 Workload                      Simple API JSON    0 ms latency          10 ms    25 ms    50 ms    CPU reduction
━━━━━━━━━━━━━━━━━━━━━━━━━━━━  ━━━━━━━━━━━━━━━━━  ━━━━━━━━━━━━━━  ━━━━━━━━━━━━━  ━━━━━━━  ━━━━━━━  ━━━━━━━━━━━━━━━
 NumPy, 1 package                       2.7 MB     2.0% faster           0.7%     2.1%     1.5%             3–4%
────────────────────────────  ─────────────────  ──────────────  ─────────────  ───────  ───────  ───────────────
 Trio, 36 packages                      7.4 MB     1.1% faster    0.8% slower     1.5%     0.0%             4–5%
────────────────────────────  ─────────────────  ──────────────  ─────────────  ───────  ───────  ───────────────
 Jupyter, 97 packages                  18.5 MB     1.8% faster           2.6%     0.9%     0.2%               7%
────────────────────────────  ─────────────────  ──────────────  ─────────────  ───────  ───────  ───────────────
 Large indexes, 26 packages            86.6 MB    19.4% faster          18.6%    18.2%    17.4%              18%

50ms would be a very good PyPI connection, and at that point with Jupyter this is only 0.2% faster.

This branch was previously deployed

1 inactive deployment
automations — 67391e88 Deployed Aug 10, 2026 by charliermarsh via review / security review #44389
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