ENG-12608: reflex-bench subjects (--reflex SPEC) and interleaved A/B runs (ab)
Linear: ENG-12608 (project P-ENG-487, Holistic Framework Benchmarks), PR-2 "Subjects and A/B". Stacked on #7274: the base is farhan/fervent-cray-2fa3k9.
All Submissions:
- Have you followed the guidelines stated in CONTRIBUTING.md file?
- Have you checked to ensure there aren't any other open Pull Requests for the desired changed?
Type of change
- New feature (non-breaking change which adds functionality)
Description
Adds the reflex under test as a choice (--reflex SPEC), each subject in its own virtualenv, and ab, which measures two subjects in alternation on one machine and compares them. Backfill uses the first (run --reflex 0.8.23), "did my branch make it faster?" uses the second (ab --base git:main --head workspace).
New CLI surface
reflex-bench run [FILTER...] [--reflex SPEC] [--python X.Y] ... # one subject, arm A
reflex-bench ab --base SPEC --head SPEC [FILTER...] [--suite NAME]
[--rounds 10] [--warmup N] [--order abba|random] [--aa] [--python X.Y]
[--param K=V] [--timeout S] [--seed N] [--keep]
[--threshold PCT] [--alpha A] [--fail-on regression|never] [--fail-on-inconclusive]
[--save/--no-save] [--save-as NAME] [--json FILE] [--ndjson]
reflex-bench subjects list # spec, python, key, size, last used
reflex-bench subjects prune [--older-than 30d] # 30d, 12h, 90m
| SPEC | Meaning |
|---|---|
workspace (default) | this checkout, in the harness's own environment (workspace_subject()) |
0.8.23, any PEP 440 version | reflex==<version> from PyPI (normalized: v0.9.12 is 0.9.12) |
git:<ref> | a commit/branch/tag of the current repository, resolved with git rev-parse --verify <ref>^{commit} |
path:<dir> | another local checkout (recorded as its absolute path) |
ab --aa takes --head only and measures it in both arms. ab shares run's parameter, timeout, seed, statistics, --fail-on, save, --json and --ndjson options (one set of option decorators for both commands).
Subject resolution (reflex_bench/subjects.py)
- One venv per subject in
<home>/venvs/<key>/, created withuv venv --relocatable --python <--python>and filled withuv pip install --python <venv python> ...; the harness is never installed in it. Every build happens in<home>/venvs/.tmp-<key>-<random>/and is renamed into place when complete, so a half-built venv is never reused;--relocatableis what makes the rename safe (console scripts such asgranianuse relative shebangs). A lock file per key (fcntl.flock,msvcrt.lockingon Windows, which also works between threads) makes concurrent runs build a venv once; the second one printswaiting for another reflex-bench to finish building venv <key>…and then reuses it. A reused venv is probed first; a broken one (base interpreter gone, reflex missing) is rebuilt. - Cache key: the first 16 hex digits of the SHA-256 of
{identity, --python, SUBJECT_REQUIREMENTS}, where the identity is the version (PyPI), the resolved commit (git), or the absolute path, commit and dirty flag (path). Apath:subject with uncommitted changes, or outside git, is rebuilt every time and says so (… (dirty, py3.12): uncommitted changes, so it is never reused…). - git subjects are checked out with
git worktree add --detachinto a temporary directory andgit worktree moved to<home>/src/<commit>/(reused when present). A worktree rather thangit archivebecause the workspace packages compute their versions from git tags (uv-dynamic-versioning); an archive would give every package the fallback0.0.0dev0. - Installing a checkout: with a
uv.lock,uv export --frozen --no-dev --no-hashes --package reflex --directory <checkout>lists-e .and every workspace package reflex needs as-e ./packages/..., with the other dependencies pinned by the lock; that list is kept in the venv asreflex-bench-requirements.txtand installed withuv pip install -rfrom the checkout (the paths are relative to the working directory). Without a lock the checkout is installed directly (-e <checkout>). v0.8.23 has auv.lockand nopackages/, and installs through the same path (verified below). - Versions are read by running the subject's interpreter on package metadata only (
importlib.metadataforreflexandgranianplusplatform.python_version()in one subprocess, run in the interpreter's directory so the working directory cannot shadow anything). The harness never imports reflex (the PR-1 import test stays green). - What happens is printed before any timing starts:
checking out …,building venv for reflex 0.8.23 (py3.12)…,built venv <key> in 14.1 s,reusing venv <key> for …. - Subject requirements:
SUBJECT_REQUIREMENTS = (). reflex 0.8.23 and HEAD both depend ongranian[reload], so reflex's own dependencies cover whatreflex runneeds from Python; a production backend started from the 0.8.23 venv works (below). The tuple stays in the key so a later addition invalidates the venvs. - The subject's commands come from its venv:
make_contextnow puts the directory of the subject's interpreter first onPATHinctx.env. reflex 0.8.23 startsgranianby name in production mode; underuv runthe harness venv is first onPATH, so without this a 0.8.23 subject served its backend with the harness's granian on the harness's Python and HEAD's reflex (evidence below).
Monorepo install evidence (git:main = 84bb6ab, built from scratch in 16.0 s):
$ .reflex-bench/venvs/6a1eb456b8dadc5a/bin/python -c "import reflex, reflex_base; print(reflex.__file__, reflex_base.__file__)"
/home/user/reflex/.reflex-bench/src/84bb6abb3227d1130007c6a91c6dc7f12b755c86/reflex/__init__.py /home/user/reflex/.reflex-bench/src/84bb6abb3227d1130007c6a91c6dc7f12b755c86/packages/reflex-base/src/reflex_base/__init__.py
Every reflex* distribution in that venv (version, direct_url.json source, editable):
reflex 0.9.12.post6.dev0+84bb6abb3 .reflex-bench/src/84bb6ab…c86 editable=True
reflex-base 0.9.12.post6.dev0+84bb6abb3 .reflex-bench/src/84bb6ab…c86/packages/reflex-base editable=True
reflex-components-code 0.9.6.post6.dev0+84bb6abb3 .reflex-bench/src/84bb6ab…c86/packages/reflex-components-code editable=True
reflex-components-core 0.9.10.post1.dev3+84bb6abb3 .reflex-bench/src/84bb6ab…c86/packages/reflex-components-core editable=True
reflex-components-dataeditor 0.9.3.post6.dev0+84bb6abb3 .reflex-bench/src/84bb6ab…c86/packages/reflex-components-dataeditor editable=True
reflex-components-gridjs 0.9.2.post1.dev3+84bb6abb3 .reflex-bench/src/84bb6ab…c86/packages/reflex-components-gridjs editable=True
reflex-components-lucide 0.0.0.post50.dev0+84bb6abb3 .reflex-bench/src/84bb6ab…c86/packages/reflex-components-lucide editable=True
reflex-components-markdown 0.9.4.post1.dev3+84bb6abb3 .reflex-bench/src/84bb6ab…c86/packages/reflex-components-markdown editable=True
reflex-components-moment 0.0.0.post50.dev0+84bb6abb3 .reflex-bench/src/84bb6ab…c86/packages/reflex-components-moment editable=True
reflex-components-plotly 0.9.7.post5.dev0+84bb6abb3 .reflex-bench/src/84bb6ab…c86/packages/reflex-components-plotly editable=True
reflex-components-radix 0.9.10.post1.dev3+84bb6abb3 .reflex-bench/src/84bb6ab…c86/packages/reflex-components-radix editable=True
reflex-components-react-player 0.0.0.post50.dev0+84bb6abb3 .reflex-bench/src/84bb6ab…c86/packages/reflex-components-react-player editable=True
reflex-components-recharts 0.9.4.post1.dev3+84bb6abb3 .reflex-bench/src/84bb6ab…c86/packages/reflex-components-recharts editable=True
reflex-components-sonner 0.9.4.post6.dev0+84bb6abb3 .reflex-bench/src/84bb6ab…c86/packages/reflex-components-sonner editable=True
reflex-hosting-cli 0.0.0.post50.dev0+84bb6abb3 .reflex-bench/src/84bb6ab…c86/packages/reflex-hosting-cli editable=True
(0.0.0.postN: no release tag of those packages is an ancestor of this commit in this clone, so uv-dynamic-versioning falls back; they install and import all the same.)
The ab algorithm (reflex_bench/ab.py)
- Both subjects are resolved (built or reused) before anything is timed;
--aaresolves--headonce and uses it for both arms. - One
Schedulerper subject (samePolicy, home and seed;Policy.runsis--rounds). Per planned instance: if either scheduler's newskip_reason()saysunsupported(too old) orskipped(a stuck hook), the whole instance gets that status with the arm as prefix (B: requires reflex >= 0.9.0 (subject has 0.8.23)). - Otherwise one entry (
new_entry(planned)) and both sessions (scheduler_a.open(planned, entry, arm="A"), then B) in acontextlib.ExitStack. - Warmups alternate A, B (
--warmup, default per benchmark),warmup=True,round= warmup index. - Timed rounds
r = 0..R-1:[A, B]for evenrand[B, A]for oddrwithabba; withrandom, a seeded coin flip per round (the shuffle of two arms) fromderive_seed(seed, instance, "order"), so an instance's order does not depend on which other instances run.session.sample_once(round=r, order=i, warmup=False)per arm. - The first failure in either arm ends the instance;
cleanupruns for both; the entry records the failure and, new, the failing arms (failed_arms). finalize(entry, confidence): it already keys summaries (and[A]/[B]warning prefixes) by arm, no change needed; tested. Then the drift check.- One document with
subjects = {"A": base.to_doc(), "B": head.to_doc()},invocation.kind = "aa"with--aa, elselocal/ci;compare.compare(doc, doc, base_arm="A", head_arm="B", …)(labelsA=<spec>/B=<spec>), the existing report code prints the run table (one row per arm) and the comparison table, then autosave and the usual exit codes (2 on a regression with--fail-on regression).
Comparing a document with itself across arms already worked for ok entries (tested). It did not for failures: the shared entry is failed whichever arm failed, so a head-only failure came out as "not compared" and exited 0 under --fail-on regression. Fixed: Session.close records its arm in failed_arms, and compare judges statuses per arm (an arm not listed only stopped early). A failure in B alone is now "failed in head" (a regression), one in A alone is "not compared: base status is failed"; documents without failed_arms behave as before.
Drift check: stats.spearman(xs, ys) (average ranks for ties, Pearson on ranks, NaN without variation; golden values from scipy.stats.spearmanr). For each arm and metric, rho between the timed values and their indices in the interleaved sequence; the metric warns drift: <metric> trends with time in arm <A|B> (rho=…, p=…) when |rho| >= 0.5 and the Spearman p-value is below 0.01.
Resource note (README, "Writing a benchmark"): during ab both arms' sessions are open from setup to cleanup, so a benchmark that keeps a server alive between samples runs two at once; start per-sample processes in prepare/sample and stop them in conclude. Not enforced.
Verification (section 5)
uv run reflex-bench run --reflex 0.8.23 --suite selftest --runs 3, first invocation (uv's cache was warm, hence the fast build):
building venv for reflex 0.8.23 (py3.12)…
built venv 3ffb620513131c23 in 0.5 s
reflex-bench 0.0.0.post54.dev0+c5dd7fac0 · reflex 0.8.23 (0.8.23) · py 3.12.3
machine: linux-x86_64 · Intel Xeon · 4 cores · vm ⚠ · load 0.75
policy: runs 3 (fixed), warmup per benchmark, timeout per benchmark, α=0.01 (Holm), threshold 3 %, CI 95 %, bootstrap 10000, seed 3028412601, fail-on never
⚠ 1 doctor warning: expect ±3–5 % extra variance (run `reflex-bench doctor`)
[1/7] selftest.exact ok · 3 samples · 0.0 s
[2/7] selftest.fail failed · 0 samples · 0.0 s
[3/7] selftest.noise[cv=5] ok · 3 samples · 0.0 s
[4/7] selftest.noise[cv=20] ok · 3 samples · 0.0 s
[5/7] selftest.sleep[ms=10] ok · 3 samples · 0.0 s
[6/7] selftest.sleep[ms=50] ok · 3 samples · 0.2 s
[7/7] selftest.timeout timeout · 0 samples · 0.5 s
selftest.exact median ± 95 % CI range n
bytes 238.4 kB (exact) 3
selftest.fail
✗ failed: RuntimeError: selftest.fail always fails
selftest.noise[cv=5]
value 0.956 s (need ≥ 6 samples) 0.887 s … 1.047 s 3
selftest.noise[cv=20]
value 1.048 s (need ≥ 6 samples) 0.923 s … 1.218 s 3
⚠ high variance: CV 14 % (warns at 10 %)
selftest.sleep[ms=10]
wall 10.12 ms (need ≥ 6 samples) 10.11 ms … 10.13 ms 3
selftest.sleep[ms=50]
wall 50.20 ms (need ≥ 6 samples) 50.17 ms … 50.21 ms 3
selftest.timeout
✗ timeout: sample() exceeded the 0.5 s timeout
7 benchmarks: 5 ok · 1 failed · 1 timeout
saved .reflex-bench/results/linux-x86_64-xeon-py3.12/0002_nogit_20260923T173816.json
Second invocation (same command) and the recorded subjects:
reusing venv 3ffb620513131c23 for reflex 0.8.23 (py3.12)
reflex-bench 0.0.0.post54.dev0+c5dd7fac0 · reflex 0.8.23 (0.8.23) · py 3.12.3
…
first: subjects.A.reflex_version = 0.8.23, python_version = 3.12.3, extra = {'granian': '2.8.3'}
second: subjects.A.reflex_version = 0.8.23, python_version = 3.12.3, extra = {'granian': '2.8.3'}
uv run reflex-bench run --reflex git:main --suite selftest --runs 3 records the resolved commit:
checking out 84bb6abb3227 into /home/user/reflex/.reflex-bench/src/84bb6abb3227d1130007c6a91c6dc7f12b755c86…
building venv for git:main (84bb6abb3227, py3.12)…
built venv 6a1eb456b8dadc5a in 16.0 s
reflex-bench 0.0.0.post54.dev0+c5dd7fac0 · reflex 0.9.12.post6.dev0+84bb6abb3 (git:main 84bb6ab) · py 3.12.3
{"spec": "git:main", "source": "git", "python": "/home/user/reflex/.reflex-bench/venvs/6a1eb456b8dadc5a/bin/python",
"python_version": "3.12.3", "reflex_version": "0.9.12.post6.dev0+84bb6abb3",
"commit": "84bb6abb3227d1130007c6a91c6dc7f12b755c86", "dirty": false, "extra": {"granian": "2.8.1"}}
The old layout (no packages/) through the same code path, run selftest.exact --reflex git:v0.8.23:
checking out 9c483e492380 into /home/user/reflex/.reflex-bench/src/9c483e4923805d0ab3a27a6c35eb8bf0a95728c5…
building venv for git:v0.8.23 (9c483e492380, py3.12)…
built venv ee10561aa0ee2232 in 22.7 s
reflex-bench 0.0.0.post54.dev0+c5dd7fac0 · reflex 0.8.23 (git:v0.8.23 9c483e4) · py 3.12.3
subjects.A = {"spec": "git:v0.8.23", "source": "git", "reflex_version": "0.8.23", "commit": "9c483e4923805d0ab3a27a6c35eb8bf0a95728c5", "dirty": false, "extra": {"granian": "2.6.0"}, …}
python -m reflex --version works from each of the three venvs (0.8.23 from site-packages; git:main and git:v0.8.23 from their worktrees).
uv run reflex-bench ab --base workspace --head workspace --suite selftest --rounds 6 (exit 0):
reflex-bench 0.0.0.post54.dev0+c5dd7fac0 · A: reflex 0.9.12.post10.dev0+c5dd7fac0 (workspace c5dd7fa, dirty) · py 3.14.7
B: reflex 0.9.12.post10.dev0+c5dd7fac0 (workspace c5dd7fa, dirty) · py 3.14.7
machine: linux-x86_64 · Intel Xeon · 4 cores · vm ⚠ · load 0.96
policy: runs 6 (fixed), warmup per benchmark, timeout per benchmark, α=0.01 (Holm), threshold 3 %, CI 95 %, bootstrap 10000, seed 3951636828, fail-on never
⚠ 1 doctor warning: expect ±3–5 % extra variance (run `reflex-bench doctor`)
[1/7] selftest.exact ok · 12 samples · 0.0 s
[2/7] selftest.fail failed · 0 samples · 0.0 s
[3/7] selftest.noise[cv=5] ok · 12 samples · 0.0 s
[4/7] selftest.noise[cv=20] ok · 12 samples · 0.0 s
[5/7] selftest.sleep[ms=10] ok · 12 samples · 0.2 s
[6/7] selftest.sleep[ms=50] ok · 12 samples · 0.7 s
[7/7] selftest.timeout timeout · 0 samples · 0.5 s
selftest.exact median ± 95 % CI range n
bytes [A] 238.4 kB (exact) 6
bytes [B] 238.4 kB (exact) 6
selftest.fail
✗ failed: RuntimeError: selftest.fail always fails
selftest.noise[cv=5]
value [A] 0.950 s ± 19 % 0.885 s … 1.129 s 6
value [B] 1.006 s ± 7.2 % 0.980 s … 1.078 s 6
selftest.noise[cv=20]
value [A] 0.963 s ± 19 % 0.824 s … 1.145 s 6
value [B] 0.968 s ± 28 % 0.749 s … 1.238 s 6
⚠ [A] high variance: CV 11 % (warns at 10 %)
⚠ [B] high variance: CV 19 % (warns at 10 %)
selftest.sleep[ms=10]
wall [A] 10.14 ms ± 0.2 % 10.11 ms … 10.15 ms 6
wall [B] 10.15 ms ± 0.3 % 10.11 ms … 10.17 ms 6
selftest.sleep[ms=50]
wall [A] 50.13 ms ± 0.3 % 50.11 ms … 50.28 ms 6
wall [B] 50.14 ms ± 0.1 % 50.13 ms … 50.21 ms 6
⚠ [A] 1 severe outlier (sample 5: +0 %). Kept.
⚠ [B] 1 severe outlier (sample 6: +0 %). Kept.
selftest.timeout
✗ timeout: sample() exceeded the 0.5 s timeout
7 benchmarks: 5 ok · 1 failed · 1 timeout
reflex-bench compare A=workspace B=workspace α=0.01 (Holm, 4 metrics) threshold=3 %
base head
selftest.exact bytes 238.4 kB 238.4 kB +0.0 % exact ~ below threshold
selftest.noise[cv=5] value 0.950 s ± 19 % 1.006 s ± 7.2 % +5.9 % [-5.2, +13] p=0.53 n=6/6 ? inconclusive (~60 runs/side needed)
selftest.noise[cv=20] value 963.1 ms ± 19 % 967.9 ms ± 28 % +0.5 % [-19, +24] p=1.00 n=6/6 ? inconclusive (more than 200 runs/side needed)
selftest.sleep[ms=10] wall 10.14 ms ± 0.2 % 10.15 ms ± 0.3 % ~ [-0.2, +0.4] p=1.00 n=6/6 no change
selftest.sleep[ms=50] wall 50.13 ms ± 0.3 % 50.14 ms ± 0.1 % ~ [-0.2, +0.1] p=1.00 n=6/6 no change
geomean (time) +1.6 % · geomean (bytes) +0.0 %
0 regressed · 0 improved · 2 inconclusive · 3 unchanged
not compared: selftest.fail: base status is failed
not compared: selftest.timeout: base status is timeout
saved .reflex-bench/results/linux-x86_64-xeon-py3.14/0003_c5dd7fa_dirty_20260923T173846.json
uv run reflex-bench ab --head workspace --aa --suite selftest --rounds 6 (exit 0; invocation.kind = aa, subjects.A == subjects.B):
reflex-bench compare A=workspace B=workspace α=0.01 (Holm, 4 metrics) threshold=3 %
base head
selftest.exact bytes 238.4 kB 238.4 kB +0.0 % exact ~ below threshold
selftest.noise[cv=5] value 1.014 s ± 3.7 % 1.010 s ± 5.8 % -0.4 % [-4.9, +2.0] p=1.00 n=6/6 ? inconclusive (~11 runs/side needed)
selftest.noise[cv=20] value 1.277 s ± 30 % 0.974 s ± 23 % -24 % [-43, -1.0] p=0.16 n=6/6 ? inconclusive (~7 runs/side needed)
selftest.sleep[ms=10] wall 10.13 ms ± 0.5 % 10.14 ms ± 0.4 % ~ [-0.4, +0.5] p=1.00 n=6/6 no change
selftest.sleep[ms=50] wall 50.13 ms ± 0.1 % 50.12 ms ± 0.1 % ~ [-0.1, +0.1] p=1.00 n=6/6 no change
geomean (time) -6.6 % · geomean (bytes) +0.0 %
0 regressed · 0 improved · 2 inconclusive · 3 unchanged
not compared: selftest.fail: base status is failed
not compared: selftest.timeout: base status is timeout
sample_meta of selftest.sleep[ms=50] in an --aa run, as (arm, round, order): warmups (A, 0, 0), (B, 0, 1), then (A, 0, 0), (B, 0, 1), (B, 1, 0), (A, 1, 1), (A, 2, 0), (B, 2, 1), (B, 3, 0), (A, 3, 1), (A, 4, 0), (B, 4, 1), (B, 5, 0), (A, 5, 1).
Across a PyPI and a git subject, ab selftest.sleep --base 0.8.23 --head git:main --rounds 8 (it happened to show a drift warning on real data):
reusing venv 3ffb620513131c23 for reflex 0.8.23 (py3.12)
reusing venv 6a1eb456b8dadc5a for git:main (84bb6abb3227, py3.12)
reflex-bench 0.0.0.post54.dev0+c5dd7fac0 · A: reflex 0.8.23 (0.8.23) · py 3.12.3
B: reflex 0.9.12.post6.dev0+84bb6abb3 (git:main 84bb6ab) · py 3.12.3
…
selftest.sleep[ms=50]
wall [A] 50.18 ms ± 0.1 % 50.18 ms … 50.26 ms 8
wall [B] 50.19 ms ± 0.1 % 50.18 ms … 50.25 ms 8
⚠ [A] 1 severe outlier (sample 8: +0 %). Kept.
⚠ drift: wall trends with time in arm A (rho=0.69)
reflex-bench compare A=0.8.23 B=git:main α=0.01 (Holm, 2 metrics) threshold=3 %
…
0 regressed · 0 improved · 0 inconclusive · 2 unchanged
subjects list and subjects prune --older-than 0m (a fake crashed build directory added first):
spec python key size last used
git:main 3.12 6a1eb456b8dadc5a 35.83 MB 2026-09-23 17:31
0.8.23 3.12 3ffb620513131c23 82.13 MB 2026-09-23 17:31
git:v0.8.23 3.12 ee10561aa0ee2232 59.49 MB 2026-09-23 17:31
3 venvs · 177.4 MB
removed /home/user/reflex/.reflex-bench/venvs/6a1eb456b8dadc5a (git:main, py3.12)
removed /home/user/reflex/.reflex-bench/venvs/3ffb620513131c23 (0.8.23, py3.12)
removed /home/user/reflex/.reflex-bench/venvs/ee10561aa0ee2232 (git:v0.8.23, py3.12)
removed /home/user/reflex/.reflex-bench/venvs/.tmp-0123456789abcdef-crashed (left by an interrupted build)
removed /home/user/reflex/.reflex-bench/src/84bb6abb3227d1130007c6a91c6dc7f12b755c86 (a git worktree no venv uses)
removed /home/user/reflex/.reflex-bench/src/9c483e4923805d0ab3a27a6c35eb8bf0a95728c5 (a git worktree no venv uses)
(git worktree list no longer lists the removed worktrees.)
PATH in ctx.env: reflex run --env prod --backend-only started from the 0.8.23 venv in a blank app, with two PATH orders; /ping answered 200 both times, and the process serving it was:
harness venv first (base_env() under `uv run`): /home/user/reflex/.venv/bin/python /home/user/reflex/.venv/bin/granian --log-level critical --host 0.0.0.0 --port 8771 …
subject venv first (make_context now): /home/user/reflex/.reflex-bench/venvs/3ffb620513131c23/bin/python /home/user/reflex/.reflex-bench/venvs/3ffb620513131c23/bin/granian --log-level …
The opt-in network test (REFLEX_BENCH_NETWORK_TESTS=1) resolves 0.8.23 for real, reads the version back and reuses the venv on a second resolve: 1 passed.
New Feature Submission:
- Does your submission pass the tests?
- Have you linted your code locally prior to submission?
Changes To Core Features:
- Have you added an explanation of what your changes do and why you'd like us to include them?
- Have you written new tests for your core changes, as applicable?
- Have you successfully ran tests with your changes locally?
Check results
| Check | Result |
|---|---|
uv run ruff check . | All checks passed! |
uv run ruff format --check . | 1593 files already formatted |
uv run pyright reflex tests packages/reflex-bench/src | 0 errors, 0 warnings, 0 informations |
uv run pytest tests/units/reflex_bench -q | 358 passed, 1 skipped (the opt-in network test) in 8.6 s; also 358 passed on Python 3.10. Package coverage 96.9 % (ab.py 100 %, subjects.py 94.9 %: uncovered are the Windows branches, the default stderr echo, a workspace without granian and malformed-manifest skips) |
REFLEX_BENCH_NETWORK_TESTS=1 uv run pytest tests/units/reflex_bench/test_subjects.py -k release_from_pypi | 1 passed |
CI=true uv run pytest tests/units --cov --no-cov-on-fail --cov-report= (as GitHub Actions runs it) | 10117 passed, 21 skipped in 175 s; "Required test coverage of 72.0% reached. Total coverage: 80.26%" |
same without CI | tests/units/test_state.py::test_state_manager_lock_expire_contend failed in 3 of 4 full runs here, also with --ignore=tests/units/reflex_bench. It uses a 300 ms lock outside CI (2500 ms with CI set), passes on its own and with the reflex-bench tests, and this PR touches neither reflex/ nor that test. |
uv run python scripts/check_min_deps.py reflex-bench | PASS (Python 3.14 and --python 3.10) |
uv run pre-commit run --files <changed files> | ruff-format, ruff-check, codespell, update-pyi-files, pyright, ty: Passed |
Tests (written before the code for each feature; a few error-path tests were added during the self-review): test_subjects.py (spec parsing and errors; cache key per version/commit/dirty/python/requirements; build once then reuse; a failed build leaves nothing; a half-built or manifest-less venv is never reused; a broken venv is rebuilt; two threads build once, the second waits; git subjects from a worktree with the exported requirements run from the checkout; a failed checkout leaves nothing; dirty and non-git path subjects are never reused; prune spares what a build holds and removes unused worktrees; the version read through a fake interpreter script; the opt-in network test), test_ab.py (ABBA for R = 1..5; seeded random order per instance; two sessions fill one entry with the right arm/round/order; a failure in either arm stops both; an arm too old or stuck skips the instance; events; drift on synthetic trends), test_cli.py (--reflex and invalid specs; ab finds a 20 % shift from a test-only benchmark whose value depends on ctx.subject.spec, registered and unregistered in a fixture; --aa gives kind="aa", equal subjects and "unchanged"/"inconclusive"; random order reproducible per seed; the self-tests under ab; usage errors; the Python mismatch warning; subjects list/prune), test_stats.py (spearman golden values from scipy.stats.spearmanr 1.18.1, ties included), test_compare.py (arms of one document; per-arm failures), test_scheduler.py (failed_arms, skip_reason, PATH), test_schema.py, report/test_table.py (header per arm). No unit test downloads anything: subjects.run, the one function that runs subprocesses, is replaced by a fake uv that still runs git for real.
Changes to PR-1 modules
Kept to what ab and subjects need. PR-1's tests pass; test_make_context gained the PATH assertion and factories.py gained make_ab_entry and an arms argument for make_doc.
scheduler.py:Session.closerecords its arm inentry["failed_arms"]; newScheduler.skip_reason(planned) -> (status, reason) | None(the unsupported/stuck checkrun_onedid inline, needed byabfor both schedulers without touching_stuck);make_contextputs the subject's interpreter directory first onPATH.compare.py: statuses are read per arm throughfailed_arms, so the arms of one document compare correctly when one arm failed.schema.py: optionalbenchmarks[].failed_arms(validated againstsubjects).stats.py:spearman.report/table.py: the header prints one line per arm.cli.py:rungains--reflex/--python;abandsubjects list|pruneare new; the optionsrunandabshare moved into_instance_options/_output_options, andrun's selection, subject resolution and saving/exit-code tail into_select/_resolve/_finish(behavior unchanged).
Deviations from the spec
- Branch: this session is pinned to
farhan/nifty-babbage-yt341oinstead offarhan/reflex-bench-subjects-ab; the PR targetsfarhan/fervent-cray-2fa3k9as asked. - Old checkouts use the same install path. v0.8.23 has a
uv.lock, so it is installed fromuv exportlike HEAD (locked dependencies, one code path); only a checkout without auv.lockis installed directly (-e <checkout>). The split is "has a lock", not "haspackages/". - Editable installs, as
uv exportemits them: they are what makesreflex/reflex_baseresolve inside the snapshot. So a git subject's venv needs its worktree (prune removes a worktree only when no venv uses it), and apath:subject runs the checkout's code live. - Key length: 16 hex digits (64 bits) of the SHA-256, to keep venv paths short (Windows path limits with the deep component packages).
- A
path:subject outside git is never reused either: its dirtiness is unknown. uv venv --relocatable: needed for the build-then-rename.resolve(spec, *, python, home, echo=…): an extra optionalechocallback (default: standard error), so the CLI can print through its console (standard error under--ndjson, which keeps stdout clean).aboptions:--headis required,--baseis required unless--aa, and--aawith--baseis a usage error. Besides the statistics/fail/save/json/ndjson options,abalso takesrun's--param,--timeout,--seedand--keep(same decorators); not--kind,--baseline,--smokeor the automatic run-count options.- Random order is a seeded coin flip per round with one stream per instance (see the algorithm). Warmup samples record
round= warmup index andorder0/1. --pythondefaults to the harness interpreter's major.minor (DEFAULT_PYTHON, fromsys.version_info), not 3.12, so aworkspacearm and a venv arm run the same Python by default (ab --base git:main --head workspacecompares like with like).--pythonstill overrides it, andabwarns when the arms' Python versions differ. The venv cache key includes the Python version.- Manifest files: each venv holds
reflex-bench-subject.json(spec, source, python request, worktree; its modification time is "last used") and, for checkouts,reflex-bench-requirements.txt(the exported dependency list). Lock files live in<home>/locks/and are never deleted (deleting a held lock file would let two processes hold "the" lock). - Extra PR-1 changes listed above:
failed_armsand per-arm statuses incompare,Scheduler.skip_reason,PATHinmake_context, the per-arm header.
Interfaces for later PRs
# reflex_bench.subjects
def resolve(spec: str, *, python: str, home: Path, echo: Callable[[str], None] = <stderr>) -> Subject
# workspace -> workspace_subject() (+ extra["granian"]); others -> built or reused venv.
# Subject.python is the venv interpreter; source is pypi|git|path|workspace; commit/dirty for git/path.
def parse_spec(text: str) -> Spec # ValueError with the expected forms
class SubjectError(Exception) # bad spec, missing ref/dir, uv failure
SUBJECT_REQUIREMENTS: tuple[str, ...] = () # extra packages for subject venvs; part of the cache key
def cached_venvs(home: Path) -> list[CachedVenv]
def prune(home: Path, older_than: timedelta, *, echo=...) -> list[Path]
# reflex_bench.ab
def run(planned: Sequence[Planned], base: Scheduler, head: Scheduler, *,
order: Literal["abba", "random"] = "abba", on_event=None) -> list[BenchmarkDoc]
def round_orders(rounds: int, order, rng: random.Random) -> list[tuple[str, str]]
def drift_warnings(entry: BenchmarkDoc) -> None
# reflex_bench.scheduler
Scheduler.skip_reason(planned) -> tuple[Status, str] | None
# reflex_bench.stats
def spearman(xs, ys) -> float # NaN without variation
- PR-3 (app driver): start the subject as
[ctx.subject.python, "-m", "reflex", …]withenv=ctx.env(subject bin first onPATH, which 0.8.x production mode needs) andcwdunderctx.workdir; start per-sample processes inprepare/sampleand stop them (process trees) inconclude, sinceabholds both arms' sessions open.setup_cachedirectories are keyed bySubject.identity(commit plus-dirty): a dirty workspace and a dirtypath:subject on the same commit share one, so do not trust cached artifacts of dirty subjects blindly. - PR-5 (CI/history): backfill is
run --reflex <version> --kind backfill; anabdocument keeps both arms (subjects.A/B, samples and summaries per arm) and exits likerun(a head-arm failure is a regression).abhas no--kindyet (it recordslocal/ci, oraa). Venvs are relocatable, but a git subject's venv also needs its worktree in<home>/src, whose.gitfile points into the repository that created it; uv's own cache already makes rebuilds fast (0.5 s for 0.8.23 here, 16 s for a HEAD checkout). Autosavedabdocuments are named after arm A's commit, asstore.autosave_namedoes for every document.
Self-review
Issues found in an adversarial pass over the diff, and what I did:
prunecould delete foreign directories: withREFLEX_BENCH_HOMEpointing at a directory that has asrc/, every subdirectory there looked like a worktree. Fixed: only names this module creates are deleted (40/64-hex commit directories,.tmp-<key>-…), each under its lock, after rechecking use.tempfile.mkdtempmade every venv mode 0700 after the rename. Fixed: the build directory is created withmkdirand a random suffix.- 0.8.x production mode would have run the harness's granian (evidence above). Fixed in
make_context, with a test. - A head-arm failure in
abwas invisible to--fail-on regression(shared entry, "not compared", exit 0). Fixed withfailed_armsand per-arm statuses, with tests. - Python mismatch between a workspace arm and a venv arm by default. Warned, with a test (see deviation 10).
- Drift warnings by chance at small n. A fixed |rho| >= 0.6 rule fired 11.5 % of the time at n = 8 and 7.3 % at n = 10 without any trend. Fixed:
stats.spearman_p(rho, n)gives a two-sided p-value (exact from all rank pairings up to n = 10, normal approximation above; golden values from scipypermutation_test(permutation_type="pairings")), and the warning needs|rho| >= 0.5andp < 0.01.test_drift_rarely_warns_without_a_trendchecks fewer than 2 % warnings in 1000 seeded trials at n = 10. - Concurrent builds of one worktree for two Pythons could race in the build hooks (they write pyi stubs into the worktree). The worktree lock is held for the whole build.
- Configuration leaks from the working directory:
uv pipreads[tool.uv]of the enclosing project, so builds run in the checkout (its own config) or, for PyPI subjects, in the bench home (for the default home that is this repository's config, e.g.exclude-newer = "7 days"with reflex packages exempt) rather than wherever reflex-bench was started. Left as is:--no-configwould also drop user-level index settings. - Known limitations: "last used" is set when a run resolves the venv, so
prune --older-thanshorter than a running benchmark can remove its venv; the Windows lock branch is only exercised by CI;subjects listwalks every venv to size it.