Repository navigation
CodSpeed: benchmark real packages (pydantic, orjson, pandas, numpy, lxml) - #19
Merged
Merged
Conversation
A new suite "packages" of codspeed-bench measures pydantic, orjson, pandas, numpy and lxml: ten benchmarks in the format of upstream's harness under .github/elide/benchmarks/packages, with their table and pinned requirements. Each iteration checks its result. The wheels are compiled on the pool with the standalone of the run (new job "wheels"): numpy without an external BLAS, pandas against it, lxml with libxml2 and libxslt linked in statically, pydantic-core and orjson with a Rust toolchain in the job's temporary directory. A check fails the job when a wheel needs a library the benchmark host may not have. "check" installs the wheels offline and runs every package benchmark briefly; "walltime" installs them into a virtual environment and runs the suite with it (--suite-python), in the same CodSpeed upload.
zlib.net serves only its latest release, so lxml's static build could not download zlib 1.3.2. Build every package even when one fails, so that one run shows all failures.
The package benchmarks are now .py files in the new folder graalpython/com.oracle.graal.python.benchmarks/python/packages, in the form of the neighbouring meso and micro benchmarks (measure, defaults on __setup__ and __benchmark__), with their table and requirements. Upstream has no such folder, so merges cannot conflict with it, and no upstream file is edited. The CodSpeed names change accordingly.
lxml's static build links libxml2 and libxslt into the extension, which fails without position-independent code. Use the flags of lxml's own Linux wheels.
Merging this PR will regress 1 benchmark1 warning
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing |
PyPI has prebuilt GraalPy wheels of pydantic-core, and the step that collects the pure Python packages fetched one, which the installation then preferred to the wheel built with the run's standalone. That step now fetches only the pure packages, and the job checks that there is one wheel per pinned package. The iterations of orjson-roundtrip, pandas-csv, pandas-groupby-merge and lxml-xpath varied by up to a factor of ten on GraalPy. These rows, and pandas-str, now repeat their work for a few rounds on smaller data. Every row runs 40 iterations. walltime-summary.json keeps the duration of every iteration.
In one run the virtual environment on the benchmark host came without pip, although the same commands worked on the pool and in the run before. package-venv, used by check and walltime, starts from an empty environment, lists it, runs pip as a module and installs pip with ensurepip when it is missing.
A manual run of elide-codspeed.yml with the input "diagnose" runs the
selected benchmarks on the benchmark host once per interpreter option
set of codspeed-diagnose.txt instead of the walltime job, and reports
nothing to CodSpeed. It keeps every iteration's duration, the GC log,
the collections per iteration and the peak RSS of each benchmark
process as an artifact. The option sets compare GraalPy's forced full
collections (background GC task, native memory limit, System.gc) and
the young generation size on the rows that vary most.
codspeed-bench takes interpreter options (--python-arg, refused when
reporting to CodSpeed), a label and a directory for each process's
output, and records each benchmark process's peak RSS.
The README said that repeating the work in ROUNDS makes the rows
steadier; the last run showed it does not. The title of the commit
that introduced ROUNDS ("steadier rows") is inaccurate for the same
reason.
The first diagnose run (46012333870) showed that the variation of orjson-roundtrip, pandas-csv, pandas-str, pandas-groupby-merge and lxml-xpath is garbage collection time: a heap that grows with every iteration on four of them, and collections forced by the native memory limit on pandas-groupby-merge.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a suite
packagesto the CodSpeed walltime workflow: ten benchmarks of real packages, compiled and measured with the native standalone of the run.Benchmarks
New folder
graalpython/com.oracle.graal.python.benchmarks/python/packages(upstream has no such folder, so merges cannot conflict with it; no upstream file is edited). One.pyper row in the format of the neighbouringmeso/microfiles (__setup__,__benchmark__,measure), run by upstream'sharness.py, with the fork's own tablebenchmarks.txtand pinnedrequirements.txt. The files carry no copyright header; upstream's style job, which this CI does not run, would flag that (noted in the README).pydantic-jsonvalidate_json/dump_jsonof nested models with a discriminated unionpydantic-modelsmodel_validatefrom dicts,model_dump, JSON round trip per modelorjson-roundtripdumps/loadsof a nested document tree, dataclassespandas-csvread_csvof an in-memory CSV,to_csv, groupbypandas-strSeries.strmethods,to_datetimepandas-groupby-mergepivot_table, rankpandas-applyapply(axis=1),Series.apply/mapwith Python functions,iterrowsnumpy-small-opsnumpy-vectorizedlxml-xpathlxml.htmlInputs come from fixed seeds in
__setup__; every iteration (or round, see below) checks its result against the expected value for its size (floats with a relative tolerance) and fails the benchmark otherwise. 40 iterations per row, the second half reported. CodSpeed names follow the existing scheme, e.g.graalpython/com.oracle.graal.python.benchmarks/python/packages/pandas-csv.py::packages/pandas-csv[50000].Versions: numpy 2.5.4, pandas 3.1.1, pydantic 2.14.3 (pydantic-core 2.50.4), orjson 3.13.0, lxml 6.1.3, plus their pure Python dependencies.
Workflow
wheels(pool, afterbuild): compiles numpy (no external BLAS/LAPACK), pandas (against that numpy), lxml (libxml2/libxslt linked statically, versions and flags of lxml's own Linux wheels), pydantic-core and orjson (Rust 1.100.0 installed into$RUNNER_TEMP) with the standalone and GraalPy's patches; only the pure packages come from PyPI, and the job checks there is exactly one wheel per pinned package (PyPI has prebuilt GraalPy wheels of pydantic-core that pip would otherwise prefer). Fails if a wheel needs a shared library beyond glibc, libstdc++ and libgcc_s. Wheelhouse artifact kept one day; nothing cached across runs.check: installs the wheels offline (.github/elide/package-venv) and runs each package benchmark for four iterations.walltime: installs the wheels offline into a venv under$RUNNER_TEMPand runs--suite micro-native meso packageswith--suite-python packages=<venv python>, in the same CodSpeed upload and the same failure check. Timeout raised from 90 to 120 minutes.codspeed-bench: suites of the fork with their own table,--suite-python SUITE=PATH,--max-iterations;walltime-summary.jsonkeeps every iteration's duration and each benchmark process's peak RSS (the process is reaped withwait4). For diagnosis:--python-arg(interpreter options, refused when reporting to CodSpeed),--label,--log-dir. Existing suites, their URIs and the printed output are unchanged.diagnose(gh workflow run elide-codspeed.yml --ref <branch> -f diagnose=true [-f variants=… -f bench=… -f iterations=…]) skipwalltimeand run the jobdiagnoseon the benchmark host: the selected rows once per interpreter option set of.github/elide/codspeed-diagnose.txtvia.github/elide/codspeed-diagnose, with every iteration's duration, the GC log, collections per iteration and peak RSS in the artifactcodspeed-diagnose-<attempt>. Nothing goes to CodSpeed; noid-token.checkfirst starts the interpreter with every option set on the pool.Measured (run 46001901569, all jobs green)
Wheel builds 8.3 min (numpy 86 s, pandas 144 s, lxml 195 s, pydantic-core 57 s, orjson 13 s);
walltime41 min, of which about 14 min for the package rows; whole workflow 59 min.Why five rows vary (diagnose run 46012333870)
Six rows, 30 iterations each, once per option set; statistics over the second half of the iterations, as reported to CodSpeed. Option sets:
default(as the benchmark job);gc-log(--vm.XX:+PrintGC, plus-u, live iteration reports and the loggerpython.capi.PythonCextBuiltinsat CONFIG, which prints each crossing of the native memory limit; the same logging is in every set below);no-bg-task(--python.BackgroundGCTask=false);no-explicit-gc(--vm.XX:+DisableExplicitGC);native-8g(no-bg-task+--python.InitialNativeMemory=8589934592);young-1g(no-bg-task+--vm.XX:InitialCollectionPolicy=BySpaceAndTime --vm.Xmn1g: the default policy, Adaptive2, only takes a maximum young size, so this changes the policy and fixes the young generation at 1 GB). One process per row and option set, so small differences between sets mean nothing; host: 62 GB RAM, no swap.orjson.loadsreturns per iteration), pandas-csv 258 MB → 2.5 GB, pandas-str 172 MB → 1.2 GB, lxml-xpath 99 → 724 MB. pydantic-json, the quiet control, stays at about 220 MB. The benchmark files keep nothing between iterations (results are small tuples, inputs are built in__setup__), and the retained memory is freed after the benchmark loop (pandas-str: 1453 MB → 188 MB in the collection after the last iteration). So GraalPy keeps these objects alive during the run; why is not known. Collections are therefore ordinary policy collections (mostly incremental) that become ever more expensive: on orjson an incremental collection takes 2–3 s and a full one 7.6 s late in the run. Forced collections play no part: the background task fires on orjson (0.4 per iteration) but turning it off leaves the spread unchanged, and no option set helps. Peak RSS is 9.5–12 GB on orjson after 30 iterations (the benchmark job runs 40).System.gc(), about 0.2 s each) and sleeps of up to 50–300 ms between retries; when seven retries do not get below the limit it is doubled. Durations follow the iteration number and are the same in every process and in the earlier normal run: 1.2 s rising to 17 s at iteration 10 (65 forced full collections, 30 crossings), 0.9 s after the limit doubles to 512 MB, rising again to 16 s at iteration 22, doubling to 1 GB. The background task plays no part (no-bg-taskis identical). Withno-explicit-gcornative-8gthe row is flat, 0.92–0.94 s (q1–q3), max 1.97 / 1.00 s; the three ~2 s iterations underno-explicit-gcare the iterations in which the limit doubles (the retry sleeps add 1.05 s). Peak RSS stays at 1.9–2.0 GB, so the forced collections buy nothing in memory here.young-1g) lowers medians where GC dominates (pydantic-json 0.87 s instead of 1.6–1.8, lxml-xpath 1.38 instead of 3.4, pandas-str 0.57 instead of 1.0) but gives worse maxima (lxml-xpath 11.8 s, pydantic-json 5.8 s) and up to three times the peak RSS (lxml-xpath 4.5 GB instead of 1.4, pydantic-json 3.0 instead of 0.9). It does not remove the spread.defaultand 1.60–1.66 s under every logged set (1.72 s in the earlier normal run). On the noisy rowsdefaultandgc-logagree.Proposal (not applied; the rows still measure GraalPy's default behaviour): keep the default interpreter options, because both causes are GraalPy behaviour that users get, and fix them in GraalPy: the retained heap on orjson/pandas/lxml, and the native memory limit's forced collections on pandas-groupby-merge (with
--python.InitialNativeMemoryat 8 GB, or explicit GC off, the row is steady at the same RSS). Until then these five rows cannot detect regressions of a few percent: either exclude them from regression alerts on CodSpeed or report them under a separate suite name. Measuring them with non-default options would hide exactly what they show.Known issues
ROUNDSon smaller data did not reduce it; the README now says so. The title of commit 9c5f666 ("…use the wheels built here, steadier rows") is inaccurate in the same way; history is not rewritten.walltime, the venv came without pip although the same commands worked before and after;package-venvnow falls back toensurepip, but that fallback has not been exercised.wheelsjob needs the network: sh.rustup.rs, zlib's GitHub release, the GNU and GNOME download servers, and PyPI for the (unpinned) build dependencies.🤖 Generated with Claude Code