Repository navigation
Closed
Labels
Description
The checker fetches PyPI's JSON in the browser and passes it to the Python driver as one string. A project's full JSON is big: https://pypi.org/pypi/numpy/json is 3.8 MB today, and most of it is fields nothing reads (description, downloads, md5_digest, comment_text, every digest of every file of every release).
Two paths carry whole documents:
check()insite/check/worker.mjs: for a requirements file orpyproject.toml, up to 300 lookups (MAX_LOOKUPS). A range or bare name fetches the project JSON. All of them are kept infetchedand sent withJSON.stringify(fetched).fixes(): thereleasesmap of up to 80 gap packages (MAX_FIX_LOOKUPS), kept in thereleasesMap for the life of the worker and sent withJSON.stringify(have).
Each document exists three times at the peak: the parsed JS object, the JSON string, and the Python object in Pyodide's heap. A requirements.txt with 40 unpinned scientific packages is hundreds of megabytes. On a phone the tab reloads, and the visitor sees the page start over with no error.
Where
site/check/worker.mjs:check()andfixes().site/check/driver.py:_fill_lookups()(what a lookup's JSON is read for) andfixes()(whatreleasesis read for), and behind them wheelgap'spypi._fill_json_data()andsuggest.suggest().
What to do
- Add
trimProject(doc)andtrimReleases(releases)tosite/check/check-logic.mjs(pure functions, so they're testable in Node). Keep only what the driver and wheelgap read. Find the list by reading the pinned wheelgap's code, not by guessing; at the time of writing it's roughly:info.requires_python,info.yanked,info.project_urls,info.home_page,info.version; for each file inurlsand in eachreleases[version]list:filename,packagetype,requires_python,yanked,upload_time_iso_8601. Say in the PR where each kept field is read. - Call them right after
r.json()in both paths, so the big object is garbage before the next request finishes. - The answer must not change.
tests/test_check_parity.pyalready compares the page with the CLI; add a case that runs the driver on a trimmed and an untrimmed copy of a recorded project JSON and gets the same result. - Later: fetch
https://pypi.org/simple/<name>/as JSON (PEP 691) for ranges, which is much smaller than the project JSON.
Done when:
-
tests/site/check-logic.test.mjscovers both functions: fields kept, fields dropped, a document that isn't the expected shape (returned in a form the driver still reports as "not PyPI's JSON", never as "no files"). -
tests/test_check_driver.pyshowscheck()andfixes()give equal results for trimmed and untrimmed input, for a pin, a range and a bare name. - In the PR: the size of the string passed to
driver.check()before and after for arequirements.txtwithnumpy,scipy,pandasandmatplotlibunpinned, and a note of the browser's memory for the tab if you can measure it.
Activity