ENG-12610: reflex-bench lifecycle benchmarks (init, compile, export, run, import) and the synthetic app generator

Draft
FA
2mo ago
+3398-102

Linear: ENG-12610, project P-ENG-487, PR-5 "Lifecycle suite", plus the synthetic app generator (moved here from PR-4). Stacked on #7280: base farhan/beautiful-carson-ldmn0u (main ← #7274 ← #7281 ← #7283 ← #7280 ← this PR). Nothing merges until the whole stack is complete.

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

The first real numbers of the harness: how long a user waits for reflex init, reflex compile (cold, warm, after one edit), reflex export, reflex run in each mode until it serves HTTP, and import reflex, on HEAD and back to 0.8.23. lifecycle.compile.warm and lifecycle.compile.incremental form the pr suite. A synthetic app generator adds the scaling curve (1 → 1000 pages) the playground cannot give.

New in packages/reflex-bench/src/reflex_bench/:

  • fixtures/__init__.py: playground_root(), describe_playground(), materialize_playground(dest), ensure_fixture(cache_dir, describe, make), bump_marker(path, target).
  • fixtures/generate.py: GenParams, describe(params), generate(dest, params), main() (uv run python -m reflex_bench.fixtures.generate --pages 10 DEST). Writes text; never imports reflex.
  • suites/lifecycle.py: the benchmarks below.

Benchmarks

IdSuitesKindOne sample
lifecycle.init.colddailytimereflex init --template blank in a fresh empty app directory with a fresh REFLEX_DIR under ctx.workdir (both deleted in prepare): bun is downloaded, the templates copied. Network-bound
lifecycle.init.warmdailytimethe same with REFLEX_DIR in ctx.cache_dir, primed by one init in setup_cache
lifecycle.compile.cold[app=playground]dailytimereflex compile of a fresh copy of the playground (made in prepare) with a fresh BUN_INSTALL_CACHE_DIR under ctx.workdir; REFLEX_DIR warm
lifecycle.compile.warm[app=playground]pr, dailytimereflex compile of the app in ctx.cache_dir/app (setup_cache: ensure_fixture + one priming compile)
lifecycle.compile.incremental[app=playground]pr, dailytimeprepare rewrites the leaf pragma line (playground/components/marker.py) to m-<n>-leaf; sample compiles
lifecycle.export.dev[app=playground], .proddailytimereflex export --env dev|prod --zip-dest-dir <ctx.workdir>/export of the primed app; prepare replaces the old zips with an empty directory (reflex needs it to exist)
lifecycle.run.dev.ready[app=playground]dailystartupAppProcess(mode="dev") of the primed app: process_ready, http_ready
lifecycle.run.prod.ready[app=playground]dailystartupmode="prod": compile + frontend build + start (two ports on 0.8.23)
lifecycle.run.preview.ready[app=playground]dailystartupmode="preview", min_version="0.9.8": unsupported on 0.8.23
lifecycle.run.backend_only.ready[app=playground]dailystartupmode="dev", backend_only=True: /ping
lifecycle.importdailytimepython -c "import reflex" in a fresh interpreter; wall only
lifecycle.scale.compile.warm[pages=1|10|100|1000]alltimeas compile.warm on a generated app; the other GenParams fields are hidden_params
lifecycle.scale.compile.incremental[pages=…]alltimeas compile.incremental, editing the first leaf target of bench-manifest.json

Cache state per id (the harness owns it; host and CI caches never reach a measured phase):

StateREFLEX_DIR (bun, templates)BUN_INSTALL_CACHE_DIRapp + .web (node_modules)
init.coldfresh per sampleuntouched (init installs no packages)fresh empty dir
init.warmctx.cache_dir/reflex, primeduntouchedfresh empty dir
compile.coldctx.cache_dir/reflex, primedfresh per samplefresh copy per sample
compile.warm, .incremental, export.*, run.*, scale.*ctx.cache_dir/reflex, primedhost defaultctx.cache_dir/app, primed by one compile
  • A host bun is hidden. reflex (both versions) runs REFLEX_DIR/bun/bin/bun, but when that is missing it takes a bun from PATH if it is new enough: MIN_VERSION is 1.3.0 in 0.8.23 and 1.4.0 at HEAD. This sandbox has bun 1.3.11 in /root/.bun/bin and /usr/local/bin (next to node), so 0.8.23 skipped its bun download (a "cold" init that was warm) and ran a different bun than HEAD. The lifecycle commands run with each PATH directory holding a bun replaced by a view (symlinks to everything else in it, in ctx.workdir), so a fresh REFLEX_DIR always downloads the subject's own bun: below, every init.cold prepare after the first deletes an 80.8 MB (HEAD, bun 1.4.0) or 104.3 MB (0.8.23, bun 1.3.4) REFLEX_DIR.
  • Metrics of time benchmarks: wall (CliResult.wall_s, returned explicitly), cpu, peak_mem (whole process tree). extra: phases (attribution()), timing, cpu_method, memory_method, peak_reset, returncode, for cold samples deleted_bytes (what prepare deleted: .web and bun cache, or .web and REFLEX_DIR; 0 before the first sample), and for incremental samples the new marker. startup benchmarks return process_ready, http_ready with readiness in extra. lifecycle.import returns wall only.
  • Collectors: CgroupScope() when CgroupScope.available() is None, else PSS sampling; phases=True. Whole-run peaks (peak_reset recorded).
  • Timeouts: each command gets 30 s less than its hook, so the driver kills a stuck command and reports it before the scheduler abandons the hook: hooks 120 s (commands 90 s), 600 s (570 s) for compile.cold, prod/preview start and every scale tier (the 1000-page tier uses 570 s, the others 90 s), setup_timeout 900 s (priming 870 s; priming a 1000-page app took ~70 s here). AppProcess gets the command timeout for start() plus 20 s for wait_http_ready().
  • warmup=1 for warm, incremental, export, run and import; 0 for cold and init. estimates come from the runs below.

The fixture record (dims)

Context gains fixture: FixtureDoc | None = None (last field). Every benchmark that drives an app (the playground or a generated one) sets ctx.fixture in setup (which always runs; setup_cache does not when a scheduler already primed the directory), and Session._setup copies it into the entry after setup succeeds:

"dims": {"fixture": "playground", "fixture_hash": "sha256:5c66b0dc30717af353d0f8b0765ac1a73207debf1fbb3a59e6d2c0b39e9226f9"}

dims are part of the pairing key (store.entry_key) and of the series key (store.series_key), so a playground edit or a generator change starts a new series. init.* and import drive no fixture and keep dims empty. The document-level fixture stays null: one invocation can drive several fixtures (--suite all runs the playground and four generated tiers), which one slot cannot describe.

ensure_fixture keeps the app in cache_dir/app with a fixture.json stamp next to it and reuses it only while the stamp equals describe(), else deletes and remakes it; the stamp is written after make returns, so a half-made app is never reused. setup_cache directories are keyed by subject identity and params, and a dirty workspace shares one with a dirty path: subject on the same commit, so the stamp is what makes a fixture change invalidate a primed app. materialize_playground copies with an ignore list mirroring examples/playground/.gitignore (.web, .states, __pycache__, *.db, *.py[cod], reflex.lock, uv.lock, .venv, uploaded_files, assets/external anchored to the app root) plus .content-hash; the hash is the committed line, never recomputed.

The generator contract

  • GenParams(pages, components_per_page=20, state_vars=20, substate_depth=2, computed_vars=5, seed=42); counts below 1 (0 for depth and computed vars) raise.

  • describe(params) → {"name": "gen", "content_hash": "sha256:" + sha256(generate.py bytes + canonical params JSON), "params": asdict(params)}. Equal params give byte-identical trees (no timestamps, no set iteration); any change of generate.py changes every generated hash.

  • Tree (app genapp): rxconfig.py with the playground's RadixThemesPlugin guard and no other plugin; genapp/genapp.py (rx.App(), page 0 at /, page i at /page-<i>); genapp/state.py (GenState(rx.State) with state_vars typed fields cycling int, str, float, bool, list[str], computed_vars @rx.var properties and an increment handler, then Sub1(GenState) … Sub<depth> each with three vars and one @rx.event handler); genapp/components/shared.py (the layout every page imports: rx.cond(GenState.is_hydrated, rx.el.span(id="bench-hydrated")) and the root target); genapp/pages/page_<i>.py (a heading and components_per_page components from rx.vstack, rx.hstack, rx.heading, rx.text, rx.button, rx.link, rx.foreach, rx.cond over the fields, computed vars, substates and handlers; consecutive pages start at consecutive fields, so the pages use them all).

  • Only import reflex as rx and APIs the playground proved on 0.8.23; the tests scan every generated module with ast and allow nothing but reflex and genapp.*.

  • Pragmas, as in the playground: NAME = "m-initial-<name>" # bench:hmr-target <name> on its own line, rendered in #bench-marker-<name>. One root target in the shared layout; leaf-<i> targets in min(pages, 10) pages drawn with random.Random(seed).sample (uniform, without replacement).

  • bench-manifest.json:

    {"targets": [
      {"name": "root", "path": "genapp/components/shared.py", "route": "/", "depth": 2},
      {"name": "leaf-3", "path": "genapp/pages/page_3.py", "route": "/page-3", "depth": 1},
      ...
    ]}
    

    depth is the import distance from the app module; route is a page showing the target, so PR-6 can navigate to it without parsing code.

Debug logging (phases=True) costs 0.04 %

reflex compile of the primed playground on HEAD, 10 × --loglevel info and 10 × --loglevel debug, interleaved ABBA after one untimed warmup, through run_cli without collectors (throwaway script, not committed):

armnmedian wallsamples (s)
--loglevel info101.1009 s1.033 1.003 1.209 1.103 1.015 1.060 1.099 1.111 1.163 1.203
--loglevel debug101.1013 s1.111 1.058 1.187 1.094 1.031 1.108 1.095 1.067 1.175 1.190

Median ratio debug/info 1.0004, below the 2 % of PLAN §8.2, so the samples are timed with phases=True (no separate untimed compile). For reference, the full local instrumentation (phases=True with its process-tree sampler, plus PSS sampling) against plain info: medians 1.1609 s vs 1.1238 s, ratio 1.033, n = 10 each, ABBA. That 3 % is the samplers, not the logging, and applies to both arms of a comparison; on a cgroup host PSS sampling is off.

Export: what a second export reuses

After priming (one compile), two exports in a row on the same app (install and frontend from the process tree):

versionenvsamplewallinstallfrontend
HEADdev15.06 s0.00 s3.74 s
HEADdev24.79 s0.00 s3.51 s
HEADprod14.82 s0.00 s3.39 s
HEADprod24.71 s0.00 s3.32 s
0.8.23dev19.55 s0.00 s8.13 s
0.8.23dev28.82 s0.00 s7.43 s
0.8.23prod18.26 s0.00 s6.74 s
0.8.23prod28.76 s0.00 s7.31 s

The second export reuses only node_modules (no install, as after priming); the frontend is rebuilt and both zips rewritten every time, within 2–8 % of the first. The docstring states it: a sample measures a primed app whose previous export is replaced (warmup 1).

Verification

All on this sandbox: a 4-core Firecracker VM (Intel Xeon, 16.9 GB), Python 3.14.7, no systemd and a hybrid cgroup v1 layout. So no cgroup scopes here: every sample records cpu_method: "rusage", memory_method: "pss_sampling", peak_reset: null; I have no cgroup host to show cgroup for both. The sandbox's environment carries BUN_OPTIONS=--smol and NODE_OPTIONS=--max-old-space-size=8192, which reach reflex through ctx.env like any host setting. HEAD is this branch at 5c2f4d6 (clean); 0.8.23 is --reflex 0.8.23 (a PyPI venv on Python 3.14).

Daily suite, --runs 5

uv run reflex-bench run --suite daily 'lifecycle.*' --runs 5 on HEAD, then with --reflex 0.8.23:

HEAD: 12 ok
lifecycle.compile.cold[app=playground]             median ± 95 % CI              range                 n
  wall                                             9.88 s (need ≥ 6 samples)     8.81 s … 13.21 s      5
  ⚠ high variance: CV 17 % (warns at 10 %)
  cpu                                              7.445 s (need ≥ 6 samples)    4.641 s … 9.596 s     5
  ⚠ high variance: CV 27 % (warns at 10 %)
  peak_mem                                         165.1 MB (need ≥ 6 samples)   162.1 MB … 180.3 MB   5
lifecycle.compile.incremental[app=playground]
  wall                                             1.126 s (need ≥ 6 samples)    1.084 s … 1.160 s     5
  cpu                                              1.112 s (need ≥ 6 samples)    1.083 s … 1.136 s     5
  peak_mem                                         83.71 MB (need ≥ 6 samples)   83.50 MB … 96.40 MB   5
  ⚠ first sample much slower: raise --warmup (modified z-score 36.9)
lifecycle.compile.warm[app=playground]
  wall                                             1.067 s (need ≥ 6 samples)    1.026 s … 1.197 s     5
  cpu                                              1.063 s (need ≥ 6 samples)    1.019 s … 1.194 s     5
  peak_mem                                         83.62 MB (need ≥ 6 samples)   83.58 MB … 97.25 MB   5
lifecycle.export.dev[app=playground]
  wall                                             4.768 s (need ≥ 6 samples)    4.527 s … 4.933 s     5
  cpu                                              6.841 s (need ≥ 6 samples)    6.655 s … 7.029 s     5
  peak_mem                                         505.9 MB (need ≥ 6 samples)   494.0 MB … 511.8 MB   5
lifecycle.export.prod[app=playground]
  wall                                             4.504 s (need ≥ 6 samples)    4.397 s … 4.763 s     5
  cpu                                              6.551 s (need ≥ 6 samples)    6.378 s … 6.761 s     5
  peak_mem                                         511.6 MB (need ≥ 6 samples)   501.2 MB … 512.1 MB   5
  ⚠ 1 severe outlier (sample 2: -2 %). Kept.
lifecycle.import
  wall                                             27.15 ms (need ≥ 6 samples)   25.83 ms … 34.57 ms   5
  ⚠ high variance: CV 13 % (warns at 10 %)
lifecycle.init.cold
  wall                                             3.429 s (need ≥ 6 samples)    3.178 s … 3.499 s     5
  cpu                                              1.459 s (need ≥ 6 samples)    1.425 s … 1.563 s     5
  peak_mem                                         69.68 MB (need ≥ 6 samples)   69.62 MB … 69.77 MB   5
  ⚠ 1 severe outlier (sample 2: +0 %). Kept.
lifecycle.init.warm
  wall                                             1.017 s (need ≥ 6 samples)    0.795 s … 1.038 s     5
  ⚠ high variance: CV 10 % (warns at 10 %)
  ⚠ 1 severe outlier (sample 4: -22 %). Kept.
  cpu                                              612.5 ms (need ≥ 6 samples)   581.9 ms … 633.0 ms   5
  peak_mem                                         56.97 MB (need ≥ 6 samples)   56.92 MB … 57.00 MB   5
lifecycle.run.backend_only.ready[app=playground]
  process_ready                                    1.024 s (need ≥ 6 samples)    0.985 s … 1.063 s     5
  http_ready                                       1.030 s (need ≥ 6 samples)    0.990 s … 1.070 s     5
lifecycle.run.dev.ready[app=playground]
  process_ready                                    2.166 s (need ≥ 6 samples)    2.059 s … 2.224 s     5
  http_ready                                       2.679 s (need ≥ 6 samples)    2.607 s … 2.756 s     5
lifecycle.run.preview.ready[app=playground]
  process_ready                                    4.583 s (need ≥ 6 samples)    4.490 s … 4.771 s     5
  http_ready                                       4.593 s (need ≥ 6 samples)    4.501 s … 4.781 s     5
lifecycle.run.prod.ready[app=playground]
  process_ready                                    4.907 s (need ≥ 6 samples)    4.597 s … 4.948 s     5
  http_ready                                       4.918 s (need ≥ 6 samples)    4.608 s … 4.961 s     5
0.8.23: 11 ok, preview unsupported
lifecycle.compile.cold[app=playground]             median ± 95 % CI              range                 n
  wall                                             9.88 s (need ≥ 6 samples)     9.40 s … 14.52 s      5
  ⚠ high variance: CV 20 % (warns at 10 %)
  ⚠ 1 severe outlier (sample 1: +47 %). Kept.
  cpu                                              10.08 s (need ≥ 6 samples)    9.60 s … 10.29 s      5
  peak_mem                                         286.4 MB (need ≥ 6 samples)   275.7 MB … 303.4 MB   5
lifecycle.compile.incremental[app=playground]
  wall                                             1.270 s (need ≥ 6 samples)    1.230 s … 1.349 s     5
  cpu                                              1.257 s (need ≥ 6 samples)    1.219 s … 1.327 s     5
  peak_mem                                         97.79 MB (need ≥ 6 samples)   97.71 MB … 97.82 MB   5
lifecycle.compile.warm[app=playground]
  wall                                             1.320 s (need ≥ 6 samples)    1.230 s … 1.368 s     5
  cpu                                              1.308 s (need ≥ 6 samples)    1.224 s … 1.349 s     5
  peak_mem                                         97.77 MB (need ≥ 6 samples)   97.71 MB … 97.88 MB   5
  ⚠ first sample much slower: raise --warmup (modified z-score 19.4)
  ⚠ 2 severe outliers (samples 1: +0 %, 2: -0 %). Kept.
lifecycle.export.dev[app=playground]
  wall                                             8.462 s (need ≥ 6 samples)    8.341 s … 9.053 s     5
  cpu                                              12.62 s (need ≥ 6 samples)    12.44 s … 13.30 s     5
  peak_mem                                         760.6 MB (need ≥ 6 samples)   751.8 MB … 762.9 MB   5
  ⚠ 1 severe outlier (sample 1: -1 %). Kept.
lifecycle.export.prod[app=playground]
  wall                                             8.365 s (need ≥ 6 samples)    8.302 s … 8.634 s     5
  cpu                                              12.57 s (need ≥ 6 samples)    12.40 s … 12.95 s     5
  peak_mem                                         743.4 MB (need ≥ 6 samples)   726.4 MB … 760.8 MB   5
lifecycle.import
  wall                                             22.17 ms (need ≥ 6 samples)   21.30 ms … 29.58 ms   5
  ⚠ high variance: CV 15 % (warns at 10 %)
  ⚠ first sample much slower: raise --warmup (modified z-score 167.1)
  ⚠ 2 severe outliers (samples 1: +33 %, 4: -4 %). Kept.
lifecycle.init.cold
  wall                                             3.990 s (need ≥ 6 samples)    3.428 s … 4.614 s     5
  ⚠ high variance: CV 12 % (warns at 10 %)
  cpu                                              2.018 s (need ≥ 6 samples)    1.934 s … 2.086 s     5
  ⚠ 2 severe outliers (samples 2: +3 %, 3: -4 %). Kept.
  peak_mem                                         101.6 MB (need ≥ 6 samples)   101.5 MB … 101.7 MB   5
lifecycle.init.warm
  wall                                             896.4 ms (need ≥ 6 samples)   844.6 ms … 932.7 ms   5
  cpu                                              880.0 ms (need ≥ 6 samples)   820.7 ms … 925.4 ms   5
  peak_mem                                         79.98 MB (need ≥ 6 samples)   79.97 MB … 80.03 MB   5
  ⚠ 1 severe outlier (sample 2: +0 %). Kept.
lifecycle.run.backend_only.ready[app=playground]
  process_ready                                    2.356 s (need ≥ 6 samples)    2.300 s … 2.379 s     5
  http_ready                                       2.378 s (need ≥ 6 samples)    2.321 s … 2.402 s     5
lifecycle.run.dev.ready[app=playground]
  process_ready                                    2.475 s (need ≥ 6 samples)    2.403 s … 2.556 s     5
  http_ready                                       3.112 s (need ≥ 6 samples)    3.052 s … 3.199 s     5
lifecycle.run.preview.ready[app=playground]
  – unsupported: requires reflex >= 0.9.8 (subject has 0.8.23)
lifecycle.run.prod.ready[app=playground]
  process_ready                                    9.188 s (need ≥ 6 samples)    9.076 s … 9.330 s     5
  http_ready                                       9.198 s (need ≥ 6 samples)    9.086 s … 9.340 s     5

12 benchmarks: 11 ok · 1 unsupported

Both as one table (medians of the timed samples):

idmetricHEAD median0.8.23 mediann (HEAD / 0.8.23)
lifecycle.compile.cold[app=playground]cpu7.445 s10.08 s5 / 5
lifecycle.compile.cold[app=playground]peak_mem165.1 MB286.4 MB5 / 5
lifecycle.compile.cold[app=playground]wall9.884 s9.883 s5 / 5
lifecycle.compile.incremental[app=playground]cpu1.112 s1.257 s5 / 5
lifecycle.compile.incremental[app=playground]peak_mem83.71 MB97.79 MB5 / 5
lifecycle.compile.incremental[app=playground]wall1.126 s1.270 s5 / 5
lifecycle.compile.warm[app=playground]cpu1.063 s1.308 s5 / 5
lifecycle.compile.warm[app=playground]peak_mem83.62 MB97.77 MB5 / 5
lifecycle.compile.warm[app=playground]wall1.067 s1.320 s5 / 5
lifecycle.export.dev[app=playground]cpu6.841 s12.62 s5 / 5
lifecycle.export.dev[app=playground]peak_mem505.9 MB760.6 MB5 / 5
lifecycle.export.dev[app=playground]wall4.768 s8.462 s5 / 5
lifecycle.export.prod[app=playground]cpu6.551 s12.57 s5 / 5
lifecycle.export.prod[app=playground]peak_mem511.6 MB743.4 MB5 / 5
lifecycle.export.prod[app=playground]wall4.504 s8.365 s5 / 5
lifecycle.importwall27.15 ms22.17 ms5 / 5
lifecycle.init.coldcpu1.459 s2.018 s5 / 5
lifecycle.init.coldpeak_mem69.68 MB101.6 MB5 / 5
lifecycle.init.coldwall3.429 s3.990 s5 / 5
lifecycle.init.warmcpu612.5 ms880.0 ms5 / 5
lifecycle.init.warmpeak_mem56.97 MB79.98 MB5 / 5
lifecycle.init.warmwall1.017 s896.4 ms5 / 5
lifecycle.run.backend_only.ready[app=playground]http_ready1.030 s2.378 s5 / 5
lifecycle.run.backend_only.ready[app=playground]process_ready1.024 s2.356 s5 / 5
lifecycle.run.dev.ready[app=playground]http_ready2.679 s3.112 s5 / 5
lifecycle.run.dev.ready[app=playground]process_ready2.166 s2.475 s5 / 5
lifecycle.run.preview.ready[app=playground]http_ready4.593 sunsupported5 / 0
lifecycle.run.preview.ready[app=playground]process_ready4.583 sunsupported5 / 0
lifecycle.run.prod.ready[app=playground]http_ready4.918 s9.198 s5 / 5
lifecycle.run.prod.ready[app=playground]process_ready4.907 s9.188 s5 / 5
  • Cold vs warm (wall medians): init 3.429 / 1.017 s = 3.37× on HEAD, 3.990 / 0.896 s = 4.45× on 0.8.23 (the bun download: every init.cold prepare after the first deleted an 80.8 MB REFLEX_DIR on HEAD, 104.3 MB on 0.8.23). compile 9.884 / 1.067 s = 9.26× on HEAD, 9.883 / 1.320 s = 7.49× on 0.8.23; every compile.cold prepare after the first deleted 140 MB of .web and 166 MB of bun cache (HEAD; 161 MB and 192 MB on 0.8.23), so each sample installed every package from the registry.
  • compile.incremental lands on compile.warm, 8–9× below cold: 1.126 s vs 1.067 s on HEAD (+5.5 %), 1.270 s vs 1.320 s on 0.8.23 (−3.8 %), both within the run-to-run spread. The phases say why: in both, install and frontend are 0, the Python compile phases sum to 0.06 s, and other (interpreter start-up, import reflex, importing and evaluating the app, .web bookkeeping) is ~1.0–1.3 s of the total. reflex compile recompiles every page whether one module changed or none, so the edit of one leaf module costs nothing measurable; cold is dominated by the package install (7.6–13.0 s of 8.8–14.5 s).

Scaling tiers, --runs 3

uv run reflex-bench run 'lifecycle.scale.*' --runs 3 on HEAD:

tiercompile.warm wallcompile.incremental wallpeak_mempython phase / other (warm)
pages=11.131 s1.156 s83.4 MB0.05 s / 1.08 s
pages=101.467 s1.459 s89.1 MB0.29 s / 1.18 s
pages=1005.872 s6.018 s144.0 MB3.09 s / 2.75 s
pages=100063.33 s63.45 s691.6 MB42.32 s / 21.18 s

Ratios: warm 100/10 = 4.00×, 1000/100 = 10.79×; incremental 100/10 = 4.12×, 1000/100 = 10.54×. Below ~100 pages the fixed start-up dominates; from 100 to 1000 pages compile time grows linearly (~64 ms per page, ~44 ms of it in the Python compile phases). Priming the 1000-page tier (generate + first compile with package install) took ~70 s, well inside setup_timeout=900.

Printed table
lifecycle.scale.compile.incremental[pages=1]      median ± 95 % CI              range                 n
  wall                                            1.156 s (need ≥ 6 samples)    1.084 s … 1.206 s     3
  cpu                                             1.134 s (need ≥ 6 samples)    1.084 s … 1.190 s     3
  peak_mem                                        95.70 MB (need ≥ 6 samples)   83.53 MB … 97.55 MB   3
lifecycle.scale.compile.incremental[pages=10]
  wall                                            1.459 s (need ≥ 6 samples)    1.438 s … 1.553 s     3
  cpu                                             1.433 s (need ≥ 6 samples)    1.428 s … 1.540 s     3
  peak_mem                                        100.9 MB (need ≥ 6 samples)   89.1 MB … 103.0 MB    3
lifecycle.scale.compile.incremental[pages=100]
  wall                                            6.018 s (need ≥ 6 samples)    5.692 s … 6.039 s     3
  cpu                                             5.956 s (need ≥ 6 samples)    5.666 s … 5.975 s     3
  peak_mem                                        144.2 MB (need ≥ 6 samples)   144.1 MB … 157.6 MB   3
lifecycle.scale.compile.incremental[pages=1000]
  wall                                            63.45 s (need ≥ 6 samples)    63.10 s … 63.53 s     3
  cpu                                             62.46 s (need ≥ 6 samples)    62.16 s … 62.50 s     3
  peak_mem                                        691.8 MB (need ≥ 6 samples)   691.7 MB … 700.1 MB   3
lifecycle.scale.compile.warm[pages=1]
  wall                                            1.131 s (need ≥ 6 samples)    1.082 s … 1.169 s     3
  cpu                                             1.099 s (need ≥ 6 samples)    1.078 s … 1.147 s     3
  peak_mem                                        83.43 MB (need ≥ 6 samples)   83.41 MB … 97.32 MB   3
  ⚠ first sample much slower: raise --warmup (modified z-score 508.2)
lifecycle.scale.compile.warm[pages=10]
  wall                                            1.467 s (need ≥ 6 samples)    1.387 s … 1.518 s     3
  cpu                                             1.454 s (need ≥ 6 samples)    1.378 s … 1.503 s     3
  peak_mem                                        89.1 MB (need ≥ 6 samples)    89.0 MB … 102.8 MB    3
  ⚠ first sample much slower: raise --warmup (modified z-score 94.3)
lifecycle.scale.compile.warm[pages=100]
  wall                                            5.872 s (need ≥ 6 samples)    5.676 s … 5.885 s     3
  cpu                                             5.779 s (need ≥ 6 samples)    5.632 s … 5.788 s     3
  peak_mem                                        144.0 MB (need ≥ 6 samples)   144.0 MB … 156.6 MB   3
lifecycle.scale.compile.warm[pages=1000]
  wall                                            63.33 s (need ≥ 6 samples)    63.12 s … 63.50 s     3
  cpu                                             62.37 s (need ≥ 6 samples)    62.21 s … 62.66 s     3
  peak_mem                                        691.6 MB (need ≥ 6 samples)   691.6 MB … 691.6 MB   3

Phase attribution

For every time sample, parts/total = (python + install + frontend + max(other, 0)) / total. All 39 samples with phases on HEAD and all 39 on 0.8.23 are at 1.000 with mismatch: false (no phases: warning in any entry); so are the 32 scale samples and the 18 of the ab and offline runs. Per sample for compile.cold and compile.warm:

HEAD:

lifecycle.compile.cold[app=playground]

samplewarmuptotal spython sinstall sfrontend sother sparts/totalmismatch
0False13.2060.06011.9760.0001.1701.000False
1False9.4140.0608.2110.0001.1431.000False
2False9.8840.1108.6240.0001.1501.000False
3False11.8030.07010.6060.0001.1261.000False
4False8.8130.0707.5580.0001.1851.000False

lifecycle.compile.warm[app=playground]

samplewarmuptotal spython sinstall sfrontend sother sparts/totalmismatch
0True1.2040.0700.0000.0001.1341.000False
1False1.0610.0600.0000.0001.0011.000False
2False1.0260.0600.0000.0000.9661.000False
3False1.1210.0600.0000.0001.0611.000False
4False1.1970.0600.0000.0001.1371.000False
5False1.0670.0600.0000.0001.0071.000False

0.8.23:

lifecycle.compile.cold[app=playground]

samplewarmuptotal spython sinstall sfrontend sother sparts/totalmismatch
0False10.1890.0608.7300.0001.3981.000False
1False14.5240.08013.0390.0001.4051.000False
2False9.8830.0608.5630.0001.2601.000False
3False9.4850.0608.1180.0001.3071.000False
4False9.4000.0807.9660.0001.3541.000False

lifecycle.compile.warm[app=playground]

samplewarmuptotal spython sinstall sfrontend sother sparts/totalmismatch
0True1.2090.0700.0000.0001.1391.000False
1False1.3200.0600.0000.0001.2601.000False
2False1.2700.0700.0000.0001.2001.000False
3False1.3540.0700.0000.0001.2841.000False
4False1.2300.0500.0000.0001.1801.000False
5False1.3680.0700.0000.0001.2981.000False

No orphans

After every run above (HEAD, 0.8.23, scale, ab, the offline run) a psutil scan for -m reflex, reflex run, granian, vite, node, bun in the command line or REFLEX_BENCH_OWNER in the environment, excluding the scanning process and its ancestors, printed no leftover processes.

Ctrl-C during lifecycle.run.prod.ready: a script starts uv run reflex-bench run lifecycle.run.prod.ready --runs 5 --no-save in its own process group, waits until the app (or one of its processes) exists, and sends SIGINT to the harness's group, as a terminal does:

=== Ctrl-C 0.3 s after `reflex run --env prod` started (workspace)
app tree at Ctrl-C: 19132 python
harness exit code: 130
app tree processes still alive: []
interrupted
no leftover processes
=== Ctrl-C 3.0 s after `reflex run --env prod` started (workspace)
app tree at Ctrl-C: 19178 python, 19194 bun, 19197 node
harness exit code: 130
app tree processes still alive: []
interrupted
no leftover processes
=== Ctrl-C 8.5 s after `reflex run --env prod` started (0.8.23)
app tree at Ctrl-C: 19260 python, 19262 python, 19263 python, 19275 bun, 19277 node
harness exit code: 130
app tree processes still alive: []
interrupted
no leftover processes
=== Ctrl-C 0.2 s after granian started (0.8.23)
app tree at Ctrl-C: 19475 python, 19477 python, 19478 python, 19587 bun, 19588 node, 19595 python, 19598 python, 19599 python
harness exit code: 130
app tree processes still alive: []
interrupted
no leftover processes

A/A

uv run reflex-bench ab --aa --head workspace lifecycle.compile.warm --rounds 4, with a poller recording every 50 ms which processes carry REFLEX_BENCH_OWNER:

[1/1] lifecycle.compile.warm[app=playground] ok · 8 samples · 13.4 s

lifecycle.compile.warm[app=playground]   median ± 95 % CI              range                 n
  wall [A]                               1.098 s (need ≥ 6 samples)    1.051 s … 1.216 s     4
  wall [B]                               1.136 s (need ≥ 6 samples)    1.053 s … 1.200 s     4
  cpu [A]                                1.094 s (need ≥ 6 samples)    1.047 s … 1.187 s     4
  cpu [B]                                1.121 s (need ≥ 6 samples)    1.045 s … 1.181 s     4
  peak_mem [A]                           95.01 MB (need ≥ 6 samples)   82.28 MB … 95.87 MB   4
  peak_mem [B]                           82.29 MB (need ≥ 6 samples)   82.20 MB … 94.71 MB   4

reflex-bench compare A=workspace B=workspace   α=0.01 (Holm, 3 metrics)  threshold=3 %
lifecycle.compile.warm[app=playground]   wall       1.098 s    1.136 s    +3.5 %   p=1.00 n=4/4   ? inconclusive (~6 runs/side needed)
                                         cpu        1.094 s    1.121 s    +2.5 %   p=1.00 n=4/4   ? inconclusive (~6 runs/side needed)
                                         peak_mem   95.01 MB   82.29 MB   -13 %    p=0.60 n=4/4   ? inconclusive (~6 runs/side needed)
0 regressed · 0 improved · 3 inconclusive · 0 unchanged

Both arms ok (A/A, inconclusive at n = 4 as expected). The poller saw owned processes in 234 of 280 polls: 198 inside a sample window (±50 ms), 36 before the first sample (the untimed priming of both arms' setup_cache) and none between samples; the orphan scan after the run found nothing. The gaps between samples are 0–2.3 ms: run_cli reaps the tree before sample() returns, and every AppProcess starts in sample and stops in conclude.

The pr suite needs no network

unshare -n -- env UV_OFFLINE=1 uv run --offline reflex-bench run --suite pr --runs 3 (a network namespace with no interface up) on the primed caches: both ok, compile.warm 1.096 s, compile.incremental 1.122 s, the same as online. Only the first priming of a new commit's cache downloads bun and packages, in setup_cache, never in a sample.

list --suite pr

$ uv run reflex-bench list --suite pr
id                                              kind   metrics                           suites     estimate
lifecycle.compile.incremental[app=playground]   time   wall (s), cpu (s), peak_mem (B)   pr,daily   ~32 s
lifecycle.compile.warm[app=playground]          time   wall (s), cpu (s), peak_mem (B)   pr,daily   ~32 s
2 benchmarks · ~65 s estimated with default settings

Opt-in slow tests

REFLEX_BENCH_APP_TESTS=1 REFLEX_BENCH_NETWORK_TESTS=1 uv run pytest tests/units/reflex_bench/suites/test_lifecycle_app.py (fresh bench home; 0.8.23 through subjects.resolve("0.8.23", python="3.12", ...)):

test_the_generated_app_compiles[1-workspace] PASSED
test_the_generated_app_compiles[1-0.8.23] PASSED
test_the_generated_app_compiles[10-workspace] PASSED
test_the_generated_app_compiles[10-0.8.23] PASSED
test_smoke_runs[daily-workspace] PASSED      (86 s: every entry ok)
test_smoke_runs[daily-0.8.23] PASSED         (95 s: every entry ok, preview unsupported)
test_smoke_runs[scale-workspace] FAILED      see below; passed on rerun (13 s)
test_smoke_runs[scale-0.8.23] PASSED

The one failure was the network, recorded as data the way it should be: priming lifecycle.scale.compile.warm[pages=10] in the fresh home got curl: (22) The requested URL returned error: 502 from github.com/oven-sh/bun/releases/download/bun-v1.4.0/bun-linux-x64.zip, so the entry is failed with that error and the run went on. The rerun 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?

Tests

Written before the code they cover; the tests of new behaviour failed first (the store test and the empty-dims tests pin behaviour that already held):

  • tests/units/reflex_bench/fixtures/test_generate.py (31): byte-identical trees for equal params; a different hash for every param and for a changed generator source (patching the bytes describe reads); page files and routes (ast over add_page); components per page; targets for 1, 7, 10 and 1000 pages (root first, 1–10 distinct leaves, each at its path with exactly one pragma line and its #bench-marker-<name>); the seed picks them; every pragma line matches ^\w+ = "m-initial-[\w-]+" # bench:hmr-target [\w-]+$; the output imports only reflex and genapp.*; the rxconfig guard; the state tree shape; every module compiles for extreme params; invalid params; a non-empty destination; main().
  • tests/units/reflex_bench/fixtures/test_fixtures.py (13): the root is found from inside the checkout; a missing .content-hash raises a clear error; the hash is the committed line; the tracked files are copied without .content-hash; the ignore list (including assets/external anchored to the root while playground/external/ and assets/externals.css are kept); ensure_fixture reuses on an equal stamp (keeping what priming added), rebuilds on a changed stamp, after an interrupted make and when the app is missing; bump_marker rewrites exactly the pragma line, continues from the number in the file and needs exactly one target.
  • tests/units/reflex_bench/suites/test_lifecycle.py (23), with run_cli and AppProcess replaced by recorders returning CliResult/Readiness built from the dataclasses: the suites and instance names; the argv, cwd and env of every id (REFLEX_DIR/BUN_INSTALL_CACHE_DIR under ctx.workdir for cold, under ctx.cache_dir for warm, host bun cache untouched otherwise); what each prepare deletes and measures; the untimed priming; compile.incremental changes exactly the pragma line, with a new value each call; the export destination is recreated empty; each run mode and backend_only; conclude stops the app when sample raised, once; the import's prefix; the scale tiers' fixture, timeouts and hidden params; ctx.fixture; the extra keys; the host bun is hidden while every other PATH tool stays reachable.
  • test_scheduler.py: the fixture lands in dims from setup_cache or setup; dims stay empty without a fixture and when setup fails; the phases: warning counts only timed samples, survives finalize(), is absent within tolerance and is per arm. test_store.py: series and entry keys differ by fixture_hash. drivers/test_app_process.py: the run_cli prefix. test_cli.py: see "Changes to lower PRs".
  • tests/units/reflex_bench/suites/test_lifecycle_app.py: the opt-in real runs above.
  • The harness-import test (test_context.py::test_the_harness_never_imports_reflex) stays green: discover() imports lifecycle, which imports the generator, and nothing loads reflex.

Check results

CheckResult
uv run ruff check .All checks passed!
uv run ruff format --check .1631 files already formatted
uv run pyright reflex tests packages/reflex-bench/src0 errors, 0 warnings, 0 informations
uv run pytest tests/units/reflex_bench -q567 passed, 10 skipped (the opt-in modules) in 25 s. Coverage: fixtures/__init__.py 100 %, fixtures/generate.py 98.6 %, suites/lifecycle.py 98.2 %, scheduler.py 98.6 %; package 94.9 %
opt-in test_lifecycle_app.py (app + network)7 passed, 1 failed on a GitHub 502, passed on rerun
uv run pre-commit run --files <changed files>ruff-format, ruff-check, codespell, update-pyi-files, pyright, ty: Passed

No news fragment: reflex-bench is in never-publish-packages, and nothing under reflex/ or a published package changed. The last commit (98bff2a) only corrects two numbers in the lifecycle.py module docstring; the runs above are on 5c2f4d6, with the same code.

Deviations from the spec

  1. Branch: this session is pinned to farhan/gallant-gauss-fs7wl5, so the PR comes from that branch instead of farhan/reflex-bench-lifecycle.
  2. Scale ids: lifecycle.scale.compile.{warm,incremental}[pages=N] instead of PLAN §8.2's lifecycle.compile.*[app=gen,pages=N]: suites are chosen per benchmark (registry.select), and the tiers belong in all but not in pr/daily.
  3. bump_marker(path, target) -> str (in fixtures, not in the spec's list): the incremental benchmarks need a value that differs from what the cached app was last compiled with. A counter that restarts at 1 per instance does not guarantee it: an earlier invocation that took one sample leaves m-1-leaf in the reused app, and the two arms of ab --aa share one cache directory, so arm B would write the value arm A just compiled, and a warm compile would be recorded as incremental. bump_marker writes m-<n+1>-<target> where n is the number in the file. Values keep the spec's m-<n>-leaf form.
  4. The host bun is hidden from the lifecycle commands (not in the spec; found by measurement, see "Benchmarks").
  5. Manifest: targets carry route besides name, path and depth, and root is listed first; depth is the import distance from the app module (pages 1, layout 2).
  6. Cold extra: deleted_bytes of init.cold counts .web and REFLEX_DIR (init installs no packages, so there is no bun cache to delete; the bun binary is in REFLEX_DIR); compile.cold counts .web and the bun cache as specified.
  7. Timeouts: the decorator values are the spec's (120 / 600 / 900 s); commands get 30 s less so the driver, not the scheduler, stops a stuck command. The 1000-page tier cannot have its own decorator timeout (timeouts are per benchmark), so both scale benchmarks declare 600 s and pick the command timeout per tier.
  8. generate() refuses a non-empty destination (stale pages from a larger app would stay behind), and GenParams rejects counts that make no app.
  9. lifecycle.import has no fixture and runs in ctx.workdir with ctx.env; it runs run_cli(python, [], prefix=("-c", "import reflex")).

Changes to lower PRs

  • context.py (PR-1): Context.fixture: FixtureDoc | None = None, last field.
  • scheduler.py (PR-1): Session._setup copies ctx.fixture into entry["dims"] once setup succeeded; finalize() appends phases: <k> of <n> samples exceed the total by more than 5 % to the wall metric (per arm, timed samples only; the 5 % is collectors.phases.MISMATCH_TOLERANCE). It reads extra["phases"].get("mismatch"), so a malformed extra cannot crash finalize(), which runs outside any try.
  • drivers/app_process.py (PR-3): run_cli(..., prefix=("-m", "reflex")).
  • README.md: a "Fixtures" section (the dims record, the playground, the generator, ensure_fixture, bump_marker) and the prefix note.
  • test_cli.py::test_list_hides_self_tests_by_default assumed the registry holds only self-tests (list printed "no benchmarks selected"). It now checks that list shows lifecycle.* and no self-test, and that an empty selection still prints the hint.

Interfaces for later PRs

  • Fixtures: app, doc = ensure_fixture(ctx.cache_dir, describe, make), with describe_playground/materialize_playground(dest) or lambda: generate.describe(params)/lambda dest: generate.generate(dest, params). Set ctx.fixture in setup (it always runs; setup_cache does not when a scheduler already primed the directory).
  • Generator: GenParams(pages, components_per_page=20, state_vars=20, substate_depth=2, computed_vars=5, seed=42), generate(dest, params) -> FixtureDoc, describe(params). genapp/bench-manifest.json (generate.MANIFEST): {"targets": [{"name", "path", "route", "depth"}, ...]}, root first, then the leaves in draw order. Every page renders #bench-hydrated once hydrated.
  • Hot reload edits (PR-6): new = bump_marker(app / target["path"], target["name"]), then wait for #bench-marker-<name> on target["route"] to show new.
  • Result index (PR-10): dims = {"fixture": <name>, "fixture_hash": "sha256:…"} on every entry that drives an app; empty otherwise. The document-level fixture stays null.
  • Driver: run_cli(..., prefix=("-c", "…")) runs other interpreter arguments through the same process tree code.
  • Host bun: _hide_bun(PATH, views) lives in lifecycle.py; the hot reload suite needs it as soon as it starts apps with a fresh REFLEX_DIR, and should move it next to cache_env.

Self-review

An adversarial pass over the diff against CLAUDE.md and the spec, with the four questions it asks first:

  1. Cache-state leaks between samples. Found two and fixed both: the host bun (a cold init on 0.8.23 did not download bun; now every init.cold prepare after the first deletes an 80–104 MB REFLEX_DIR), and the incremental counter (see deviation 3). The data shows the rest holds: every compile.cold prepare deletes 140–161 MB of .web and 166–192 MB of bun cache, so no sample installs from a warm cache; every warm, incremental and export sample has install = 0 (nothing reinstalled, no hidden cold step); the registry-latency probe reflex runs on a fresh REFLEX_DIR is cached in the primed one (reflex_best_registry.cached), so it only lands in init.cold, where the spec wants it.
  2. Processes left after a timeout. Commands time out 30 s before their hooks, so run_cli kills and reaps its tree before the scheduler could abandon the hook; AppProcess.start() gets the command timeout and wait_http_ready() 20 s within the margin, and conclude stops the app from any thread. Ctrl-C at four points left nothing. Limitation: with a --timeout lower than a command's own timeout, an abandoned run_cli keeps its tree until that timeout (then kills it) or until exit (atexit), and the scheduler keeps the work directory.
  3. Fixtures reused across a hash change. The stamp rebuilds on any change of the committed playground hash or of generate.py, and a half-made app has no stamp. Limitation by design: an edit of the playground that is not yet re-hashed (pre-commit or scripts/hash_examples.py) is not seen, since the hash is never recomputed.
  4. A pr-suite benchmark that depends on the network. Verified offline (above). The first priming of a new commit's cache needs the network (bun download, package install into bun's cache), in setup_cache only.

Other findings, left as they are:

  1. tests/units/reflex_bench/test_scheduler.py::test_interrupt_runs_conclude_on_a_fresh_thread (PR-1) failed once while a compile loaded all 4 cores: the abandoned worker picked up the queued sample job after conclude and cleanup had run, so calls[-2:] ended with sample. The test races with its own worker; it passed 5/5 on an idle machine and in every later run. Not touched here.
  2. CliResult.check() names the command reflex <args>, so a failed import would read "reflex exited with code 1" above the traceback.
  3. Host environment variables reach reflex through ctx.env (PR-1's policy); on this sandbox that includes BUN_OPTIONS=--smol and NODE_OPTIONS=--max-old-space-size=8192.
  4. Network-bound benchmarks: init.cold downloads bun (a 37 MB zip for 1.4.0, 39 MB for 1.3.4) and probes two npm registries, compile.cold fills a fresh bun cache with 166–192 MB of packages per sample (CV 17–20 % here). A transient 502 fails the priming of an instance (seen once, above); no retry.
  5. Disk: every benchmark instance keeps its own REFLEX_DIR (78–104 MB of bun) and primed app per subject commit (node_modules are hard links into bun's cache); nothing prunes old commits' cache directories yet (subjects prune handles venvs), which PR-11 will want in CI.
  6. The benchmark version hashes the class source only, so a change in the shared base classes or helpers of lifecycle.py keeps the version (as for any shared helper since PR-1).
  7. estimate is per benchmark, so the scale tiers share one (18 s, the mean of 1.1–63 s).
  8. The generated rxconfig.py has no SitemapPlugin, as specified, so both versions print their "enabled by default" warning on every compile.
  9. Two concurrent invocations sharing a cache directory could race in ensure_fixture (no cross-process lock; the same holds for every setup_cache since PR-1).

Review fixes (61b6e058e)

These supersede the matching parts above.

  1. An edited fixture is reported, not silently dropped. dims now hold only the fixture name ({"fixture": "playground", "collector": …}). fixture_hash is an entry-level field that is part of the series key but not the pairing key. So after a playground or generator edit, compare reports not compared: …: fixture content hash differs: sha256:… vs sha256:… instead of listing both ids as unpaired and skipping the gate; --force compares them. (Lower-PR changes: schema optional fixture_hash, store.series_key, scheduler.Session._setup.)
  2. lifecycle.import measures the framework: it runs import reflex as rx; rx.App; rx.State in a fresh interpreter. import reflex alone is lazy (~10 modules), so the old 22–27 ms numbers were mostly interpreter start-up. Measured now: ~0.49 s, 58 → 1032 modules.
  3. Collector in dims: time benchmarks decide the collector once in setup and record dims["collector"] = "cgroup" | "fallback", so cgroup and fallback numbers never share a series. New Context.dims, copied into the entry by the scheduler.
  4. One REFLEX_DIR per subject: warm benchmarks share <home>/cache/<subject>/reflex, so a commit downloads bun once instead of once per instance. init.cold still uses its own fresh one.
  5. Incremental edits are restored: conclude restores the edited module. Markers stay unique across ab arms (bump_marker(path, target, n) with a shared counter). The cached app matches its recorded .content-hash after runs.
  6. No late start after a timeout: _Ready builds the AppProcess in prepare and stops it in conclude, so a timed-out sample cannot start an app after teardown.
  7. Trimmed (~95 lines net): functools.partial for the repeated @benchmark kwargs; _Primed.fixture(ctx); over-defensive GenParams/generate() checks removed; ensure_fixture returns the path.

Checks: 566 passed, 10 skipped; ruff, pyright and pre-commit pass. Real runs (cgroup): compile.warm 711 ms, incremental 670 ms, import 491 ms (n=3); compile.cold 48.6 s with .web and the bun cache really deleted.

Phase attribution rework (43f2342cb)

This supersedes the "Phase attribution" section above: the other bucket, parts/total and the 5 % rule. On warm compiles python was 0.04 s and other 0.6 s, because only the [timing] log labels counted as Python, and the 5 % check could never fire.

Now collectors/phases.attribute(total_s, cpu_s, timing, tree) works per process class. TreePhases records the root too, and every process gets one class:

  • install: bun/npm/pnpm/yarn install|add|i|ci, and what they start;
  • frontend: node, vite, react-router, esbuild, and what they start;
  • python: everything else.

Reported per sample in extra["phases"]:

  • wall per class: a tool class is the union of its process lifetimes, clipped to the total. python = total − |install ∪ frontend|, since the interpreter only waits while those run.
  • cpu per class from sampled cpu_times, and cpu_total from the cgroup cpu.stat (or rusage).
  • mismatch: true when the per-class CPU sum is off cpu_total by more than 10 % (MISMATCH_TOLERANCE). This is a real cross-check that can fail.
  • idle: the sum over classes of max(wall − cpu, 0), for example network waits during a cold install.
  • python_breakdown: the [timing] labels (minus install), nested under Python.

Small changes to lower-PR files: collectors/phases.py and drivers/app_process.py (#7283: attribution() passes cpu_s), and scheduler.py (#7274: the phase warning text).

Checks: 571 passed, 10 skipped; ruff, pyright and pre-commit pass. Real verification follows after the running benchmark comparison.

Cold samples without the network (7716d127f)

lifecycle.compile.cold and lifecycle.init.cold measured the network and the npm registry, not Reflex. init.cold downloaded bun (~80 MB) in every sample (31–35 s). compile.cold emptied bun's package cache and downloaded every package (51–77 s, depending on registry speed).

  • compile.cold: each sample still gets a fresh app copy with no .web and no node_modules, and the subject's primed bun package cache is shared. The fix is the lockfile. A fresh copy without one made bun add fetch every package manifest from the registry even with a full cache (bun's --prefer-offline and BUN_MANIFEST_CACHE don't help a lockfile-less bun add). prepare now copies the priming compile's lockfile into the copy (reflex.lock/ on 0.9, .web/bun.lock on 0.8), so the install links everything from the cache.
  • init.cold: each sample still gets a fresh project and a fresh REFLEX_DIR, but bun is copied in from the subject's primed REFLEX_DIR (untimed), so nothing is downloaded.

Verified:

  • strace on the timed install: 0 bytes to any outside socket.
  • With the registry pointed at 127.0.0.1:9, HEAD passes (with the lockfile), and 0.8.23 passes with or without it.

Real runs, --runs 3:

HEAD0.8.23
compile.cold941 ms985 ms
init.cold4.08 s~4 s

Before: 51–77 s and 31–35 s.

New test: test_compile_cold_prepare_copies_the_primed_lockfiles; 572 passed; pre-commit passes.