Skip to content

CodSpeed: benchmark real packages (pydantic, orjson, pandas, numpy, lxml) - #19

Merged
Ivo Horák (horakivo) merged 8 commits into
developfrom
ci/codspeed-packages
Nov 27, 2026
Merged

Ivo Horák (horakivo) merged 8 commits into
developfrom
ci/codspeed-packages

Conversation

@horakivo

@horakivo Ivo Horák (horakivo) commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Adds a suite packages to 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 .py per row in the format of the neighbouring meso/micro files (__setup__, __benchmark__, measure), run by upstream's harness.py, with the fork's own table benchmarks.txt and pinned requirements.txt. The files carry no copyright header; upstream's style job, which this CI does not run, would flag that (noted in the README).

Benchmark What it measures
pydantic-json validate_json / dump_json of nested models with a discriminated union
pydantic-models model_validate from dicts, model_dump, JSON round trip per model
orjson-roundtrip dumps / loads of a nested document tree, dataclasses
pandas-csv read_csv of an in-memory CSV, to_csv, groupby
pandas-str Series.str methods, to_datetime
pandas-groupby-merge merge, groupby aggregations, pivot_table, rank
pandas-apply apply(axis=1), Series.apply/map with Python functions, iterrows
numpy-small-ops many 3-element arrays from a Python loop
numpy-vectorized ufuncs, reductions, sort, FFT on large arrays
lxml-xpath XML parse, XPath, serialization, lxml.html

Inputs 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

  • New job wheels (pool, after build): 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_TEMP and runs --suite micro-native meso packages with --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.json keeps every iteration's duration and each benchmark process's peak RSS (the process is reaped with wait4). For diagnosis: --python-arg (interpreter options, refused when reporting to CodSpeed), --label, --log-dir. Existing suites, their URIs and the printed output are unchanged.
  • Manual runs with the input diagnose (gh workflow run elide-codspeed.yml --ref <branch> -f diagnose=true [-f variants=… -f bench=… -f iterations=…]) skip walltime and run the job diagnose on the benchmark host: the selected rows once per interpreter option set of .github/elide/codspeed-diagnose.txt via .github/elide/codspeed-diagnose, with every iteration's duration, the GC log, collections per iteration and peak RSS in the artifact codspeed-diagnose-<attempt>. Nothing goes to CodSpeed; no id-token. check first 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); walltime 41 min, of which about 14 min for the package rows; whole workflow 59 min.

Row Median s q1 q3 min max
pydantic-json 1.72 1.66 1.80 1.58 1.96
pydantic-models 1.35 1.32 1.37 1.31 1.51
orjson-roundtrip 3.40 2.31 7.20 0.84 11.42
pandas-csv 2.54 2.30 4.33 1.79 5.81
pandas-str 1.01 0.99 1.83 0.85 2.28
pandas-groupby-merge 1.44 1.09 1.92 0.88 15.56
pandas-apply 1.17 1.15 1.35 1.04 1.49
numpy-small-ops 0.60 0.60 0.61 0.56 0.86
numpy-vectorized 0.69 0.68 0.86 0.68 0.88
lxml-xpath 3.52 2.70 3.87 2.60 5.14

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 logger python.capi.PythonCextBuiltins at 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.

Row Option set median s q1 q3 min max GC pause s/iter (incr. + full) forced full GCs/iter peak RSS GB
orjson-roundtrip default 3.56 2.60 7.22 0.85 8.89 – – 9.5
orjson-roundtrip gc-log 3.44 2.79 6.32 0.91 7.70 3.03 (1.54 + 1.49) 0.4 10.1
orjson-roundtrip no-bg-task 3.54 1.94 4.23 0.85 10.22 2.41 (1.53 + 0.88) 0.0 11.6
orjson-roundtrip no-explicit-gc 3.65 1.92 4.37 0.87 10.33 2.43 (1.55 + 0.88) 0.0 12.0
orjson-roundtrip native-8g 3.58 1.97 4.32 0.86 10.30 2.45 (1.55 + 0.90) 0.0 11.6
orjson-roundtrip young-1g 2.43 2.10 4.81 0.94 9.78 2.33 (0.99 + 1.34) 0.0 9.5
pandas-csv default 2.42 2.20 4.04 1.84 5.21 – – 4.3
pandas-csv gc-log 2.36 2.23 4.03 1.89 4.81 1.66 (0.91 + 0.76) 0.1 4.5
pandas-csv no-bg-task 2.52 2.23 3.47 2.04 5.48 1.66 (0.97 + 0.69) 0.0 4.6
pandas-csv no-explicit-gc 2.52 2.24 3.36 1.93 5.08 1.62 (0.93 + 0.69) 0.0 4.6
pandas-csv native-8g 2.34 2.19 3.36 1.87 5.29 1.63 (0.94 + 0.69) 0.0 4.6
pandas-csv young-1g 1.93 1.43 2.21 0.95 7.95 1.32 (0.39 + 0.92) 0.3 5.6
pandas-str default 1.00 0.89 1.68 0.84 1.96 – – 2.7
pandas-str gc-log 0.95 0.92 1.66 0.85 2.03 0.66 (0.31 + 0.35) 0.0 2.7
pandas-str no-bg-task 1.05 0.99 1.65 0.86 1.79 0.63 (0.34 + 0.29) 0.0 2.7
pandas-str no-explicit-gc 1.05 0.98 1.66 0.87 1.77 0.65 (0.31 + 0.34) 0.0 2.7
pandas-str native-8g 1.03 0.96 1.71 0.86 2.03 0.68 (0.33 + 0.35) 0.0 2.6
pandas-str young-1g 0.57 0.54 0.95 0.53 2.18 0.29 (0.11 + 0.17) 0.0 3.9
pandas-groupby-merge default 1.89 1.04 2.89 0.87 15.72 – – 1.9
pandas-groupby-merge gc-log 1.92 1.04 2.65 0.87 15.68 1.81 (0.01 + 1.81) 8.1 1.9
pandas-groupby-merge no-bg-task 1.91 0.91 2.90 0.89 15.70 1.77 (0.01 + 1.76) 7.9 1.8
pandas-groupby-merge no-explicit-gc 0.93 0.92 0.94 0.91 1.97 0.02 (0.02 + 0.00) 0.0 1.9
pandas-groupby-merge native-8g 0.93 0.92 0.94 0.91 1.00 0.02 (0.02 + 0.00) 0.0 1.9
pandas-groupby-merge young-1g 1.85 1.41 2.80 0.84 15.14 1.85 (0.00 + 1.85) 8.6 2.4
lxml-xpath default 3.37 2.68 3.49 2.55 4.19 – – 1.3
lxml-xpath gc-log 3.34 3.06 3.70 2.55 4.26 1.69 (1.01 + 0.67) 0.1 1.4
lxml-xpath no-bg-task 3.42 3.02 3.72 2.65 3.88 1.62 (0.96 + 0.66) 0.0 1.4
lxml-xpath no-explicit-gc 3.45 2.74 3.60 2.59 4.06 1.56 (0.95 + 0.62) 0.0 1.4
lxml-xpath native-8g 3.45 2.64 3.65 2.50 3.84 1.51 (0.92 + 0.59) 0.0 1.4
lxml-xpath young-1g 1.38 1.31 4.58 1.26 11.76 1.56 (0.66 + 0.91) 0.0 4.4
pydantic-json default 1.81 1.74 1.86 1.65 1.96 – – 0.8
pydantic-json gc-log 1.60 1.58 1.68 1.50 2.62 0.75 (0.64 + 0.11) 0.0 0.9
pydantic-json no-bg-task 1.60 1.60 1.63 1.48 2.33 0.65 (0.60 + 0.05) 0.0 0.9
pydantic-json no-explicit-gc 1.66 1.62 1.68 1.50 2.40 0.68 (0.64 + 0.04) 0.0 0.9
pydantic-json native-8g 1.61 1.57 1.68 1.53 2.51 0.73 (0.62 + 0.10) 0.0 0.9
pydantic-json young-1g 0.87 0.83 1.95 0.75 5.80 0.67 (0.20 + 0.47) 0.0 3.0
  • The variation is GC pause time. On every row the iteration's duration correlates with the GC pause inside it at 0.98 to 1.00, and GC pauses are 40 to 70% of the time. Without the pauses the spread is small (orjson q1–q3 1.00–1.40 s instead of 2.79–6.32 s; pandas-str 0.60–0.62; lxml-xpath 1.65–1.76; pandas-csv 1.21–1.35). An iteration is fast or slow depending on whether a collection falls into it; that is the alternation seen before.
  • orjson-roundtrip, pandas-csv, pandas-str, lxml-xpath: a heap that grows every iteration. The heap left after a full collection grows about linearly with the iteration number: orjson 134 MB → 3.3 GB after 22 iterations (about 110 MB per iteration, roughly the size of the 20 documents orjson.loads returns 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).
  • pandas-groupby-merge: the native memory limit. The heap stays at 143 MB, but native allocations cross GraalPy's native memory limit (256 MB at start) more often in every iteration; each crossing forces full collections (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-task is identical). With no-explicit-gc or native-8g the row is flat, 0.92–0.94 s (q1–q3), max 1.97 / 1.00 s; the three ~2 s iterations under no-explicit-gc are 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 generation (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.
  • Logging is not neutral everywhere: pydantic-json takes 1.81 s under default and 1.60–1.66 s under every logged set (1.72 s in the earlier normal run). On the noisy rows default and gc-log agree.

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.InitialNativeMemory at 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

  • orjson-roundtrip, pandas-csv, pandas-str, pandas-groupby-merge and lxml-xpath vary by up to a factor of ten between iterations, for the GC reasons above. Repeating the work in ROUNDS on 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.
  • orjson-roundtrip peaks at about 10–12 GB RSS after 30 iterations, and the retained heap keeps growing; with 40 iterations in the benchmark job it is more, on a host shared with other jobs.
  • orjson-roundtrip and lxml-xpath are above 3 s per iteration; resizing needs new expected values and a run.
  • Once, in walltime, the venv came without pip although the same commands worked before and after; package-venv now falls back to ensurepip, but that fallback has not been exercised.
  • The wheels job 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

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.
@horakivo Ivo Horák (horakivo) added the perf:bench Runs walltime bench on our infra label Nov 27, 2026
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.
@codspeed

codspeed Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Merging this PR will regress 1 benchmark

1 warning

⚠️ Walltime results may be unreliable

Some benchmarks used the Walltime instrument outside CodSpeed Macro Runners, which can make the results inconsistent.

Learn more about Macro Runners

See affected benchmarks

⚡ 3 improved benchmarks
❌ 1 regressed benchmark
✅ 52 untouched benchmarks
🆕 10 new benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ micro-native/c-arith-binop2[100] 3 s 3.7 s -17.42%
⚡ meso/euler31[200] 3.6 s 2.4 s +47.06%
⚡ meso/pidigits 7.4 s 6.3 s +17.94%
⚡ meso/parrot-b2[200] 1.3 s 1.1 s +15.69%
🆕 packages/numpy-small-ops[600] N/A 552.5 ms N/A
🆕 packages/numpy-vectorized[4000000] N/A 678.3 ms N/A
🆕 packages/pandas-apply[20000] N/A 1.1 s N/A
🆕 packages/pydantic-json[8000] N/A 1.5 s N/A
🆕 packages/pydantic-models[10000] N/A 1.3 s N/A
🆕 packages/lxml-xpath[2500] N/A 2.5 s N/A
🆕 packages/orjson-roundtrip[2500] N/A 869 ms N/A
🆕 packages/pandas-csv[50000] N/A 1.4 s N/A
🆕 packages/pandas-groupby-merge[150000] N/A 876.4 ms N/A
🆕 packages/pandas-str[20000] N/A 817.1 ms N/A

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing ci/codspeed-packages (1df9f22) with develop (17ac452)

Open in CodSpeed

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.
@horakivo
Ivo Horák (horakivo) marked this pull request as ready for review November 27, 2026 23:33
@horakivo
Ivo Horák (horakivo) merged commit aab494f into develop Nov 27, 2026
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

perf:bench Runs walltime bench on our infra

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant