ENG-12611: reflex-bench browser readiness (tier 3), page load and hot reload benchmarks
PR-6 of the Holistic Framework Benchmarks project (ENG-12611, plan item "PR-6 Browser readiness and hot reload"). Stacked on #7280 (farhan/beautiful-carson-ldmn0u): main ← #7274 ← #7281 ← #7283 ← #7280 ← this. Nothing merges until the project is done.
Adds a Playwright browser driver, readiness tier 3 (interactive_ready), a prod page load benchmark and the hot reload benchmarks (hmr.*). The harness still never imports the reflex under test (PR-1's import test stays green); playwright >=1.49 is a new reflex-bench dependency. reflex-bench is never published, so no news fragment. PR-5 (lifecycle, app generator) is not needed: FIXTURES is the extension point it can fill.
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)
New Feature Submission:
- Does your submission pass the tests?
- Have you linted your code locally prior to submission?
Changes To Core Features:
Not applicable: nothing under reflex/ changes; the changes are in packages/reflex-bench (never published), its tests and uv.lock.
What this adds
| Module | |
|---|---|
drivers/browser.py + drivers/bench_page.js | Browser (Playwright lifecycle, thread rules, kill), Tab (a page in its own context and what it reported), Anchor (clock alignment), Interactive (tier 3) |
drivers/editor.py | find_target (the # bench:hmr-target literal), text_target, Edit (content built in memory, one os.replace right after t0, byte-identical restore) |
fixtures/__init__.py | playground_dir(), stage_playground(dst), FIXTURES, prime(ctx) (stage + one warm-up reflex compile), app_dir(ctx), app_env(ctx, app), fixture_hash() |
suites/browser.py | browser.{dev,preview,prod}.ready, browser.prod.pageload[cpu=1|4] |
suites/hmr.py | hmr.render.leaf, hmr.render.root, hmr.handler, hmr.css, hmr.asset, hmr.reconnect, hmr.watcher, and a .preview twin of each but hmr.watcher |
drivers/app_process.py | AppProcess.t0, AppProcess.log_lines(), and the owner scan exposed as owned_processes() / kill_owned() (see "Changes to lower PRs") |
playwright >=1.49 joins reflex-bench's dependencies. Neither the Python nor the JS release notes mention --only-shell, so the evidence comes from playwright install --help of the 1.48.0 and 1.49.0 wheels (from PyPI):
== playwright 1.48.0
--with-deps install system dependencies for browsers
--force force reinstall of stable browser channels
== playwright 1.49.0
--with-deps install system dependencies for browsers
--force force reinstall of stable browser channels
--only-shell only install headless shell when installing chromium
Import time was measured before deciding where to import it: python -X importtime -c "import playwright.sync_api" is 84–104 ms cumulative, and reflex-bench list takes ~205 ms wall, so a top-level import would add ~50 % to list. Browser.start() imports it; a unit test checks that importing the driver loads no playwright module, and PR-1's no-reflex-import test stays green.
Browser API and thread rules
browser = Browser(headless=True, cpu_throttle=1)
browser.start() # sync_playwright().start(), chromium.launch(env={..., REFLEX_BENCH_OWNER: token})
tab = browser.new_page() # fresh context (cold cache), bench_page.js as init script, CDP session (CPU throttle)
result = browser.interactive(app, "/") # goto(commit) + wait_for_selector(#bench-hydrated, attached); fills app.readiness.interactive_ready
browser.close_tab(tab) # context.close() on the owner thread, kill() elsewhere
browser.close() # owner thread: browser.close() + playwright.stop(), then a kill() sweep; any other thread: kill()
browser.kill() # any thread, idempotent, never touches Playwright
Tab wraps the page: watch(id, kind, selector, expected) / unwatch / mark / poll_mark / wait_mark, read / wait_value, set_alive / alive, wait_quiet, click, reload, settle, timings(), transfer_bytes(), raise_errors() (page errors fail a sample; page_errors holds them until then), drain_console() (errors and warnings counted into extra; last_error keeps the last error's text), ws_bytes and ws_events (from page.on("websocket") frames), cdp.
- Owner thread.
start()recordsthreading.current_thread()(the object, notget_ident(): idents are reused after a thread exits, and the scheduler's fresh teardown thread could get the dead owner's).new_page()refuses other threads;close()andclose_tab()fall back tokill()on them. kill()SIGKILLs every process carrying the owner token and their descendants (Chromium starts its zygotes, renderer, GPU and network processes with an empty environment, so the token alone finds only the browser root: measured below), the process groups they lead (Chromium's helpers stay in the root's group, which also catches a helper spawned after the scan), and the Playwright node driver, found at start as the parent of the owned browser root that is the harness's own child. The driver does not carry the token (Playwright starts it with the harness's environment; putting the token there would mean mutatingos.environunder other threads). Guards are PR-3's (_signal,_signal_group: never pid/pgid <= 1, the harness or its group); the scan repeats 3 times for late spawns, like_ProcessTree.kill.- An abandoned hook blocked in the page gets an error at once: measured with the owner thread blocked in
wait_for_selector("#never", timeout=60 s),kill()from another thread made it raisePage.wait_for_selector: Connection closed while reading from the driverafter 8 ms (14 ms andTargetClosedErrorwhen only Chromium is killed, but then the driver lingers until the harness exits, which is why the driver is killed too). start()rechecks after launching: akill()from another thread during a slowstart()kills again and raises.atexitkills browsers still open (registered after PR-3's tree killer, so it runs first).- Browsers are never shared between instances or arms; during
abtwo coexist.
Clock alignment
AppProcess.t0 (new, read-only) is the perf_counter() taken just before Popen; readiness and log times count from it. Browser.start() takes the Anchor: perf_counter(), time(), perf_counter() read back to back, three times, keeping the pair with the smallest spread (perf = middle of the two reads). A page time maps as anchor.perf_at(epoch_ms / 1000) - app.t0. Marks carry performance.now() and Date.now(); the page's navigation start is mark.epoch - mark.perf, and paint times map through it, so every page time goes through the same Date.now() clock (performance.timeOrigin + perf agreed with Date.now() within 0.3 ms). Every sample stores anchor_spread_s.
Tier 3 per mode and version
interactive_ready is the moment the page itself recorded #bench-hydrated as attached (the init script's MutationObserver, in every document), mapped onto the app's t0; the harness only waits for it with wait_for_selector(..., state="attached"). The playground renders #bench-hydrated from rx.cond(BenchState.is_hydrated, ...): the websocket connected and the hydrate event's first delta applied, on both versions. Tiers 1 and 2 are PR-3's, unchanged. What happens before tier 3 differs (both versions build with ssr: false, checked in each staged app's .web/react-router.config.js):
| Mode | HEAD (0.9.12.dev) | 0.8.23 |
|---|---|---|
| dev | vite dev server + backend, two ports; the page is served as unbundled modules, so nav_to_interactive is ~1.1 s and fcp comes with hydration | same topology; nav_to_interactive ~0.85 s |
| preview | one port: the backend serves the static build, so http_ready follows process_ready by 10 ms | unsupported (min_version="0.9.8") |
| prod | one port, the frontend build is part of the start | sirv on its own port + backend; the build is part of the start (~8 s) |
The medians per mode and version are under Verification.
Hot reload method
See the suites/hmr.py docstring and the README's "Hot reload benchmarks". Per sample: prepare waits until the page is quiet (no pending watch, no DOM mutation for 0.5 s), tags the document (__BENCH_ALIVE), builds the new file content and arms a persisted watch for a unique value (m-<12 hex> for the literals; a font size / logo width that differs from the original and from the previous edit for css/asset); sample writes it (t0 = time.time_ns() right before the one os.replace), waits for the page's mark, waits until quiet, reads the tag back; latency = mark.epoch − t0; conclude restores and waits for the original value plus quiet. The watch is stored in sessionStorage and re-armed by the init script in a reloaded document, and so is its mark once recorded, so a hot reload that turns into a full reload still produces a mark (and wait_for_function survives the navigation), and the lost tag classifies it.
- Full reloads (a lost tag):
hmr.render.*,hmr.handlerandhmr.reconnectrestore, settle and retry with a new value, up to 3 tries, counting each infull_reloads, then raiseFullReloadError;latencyonly ever holds a hot update.hmr.css/hmr.assettime the change by whatever means shows it and record the reload infull_reloads. - Clicks:
hmr.handlerandhmr.reconnectclick every 250 ms until the page's watch fires (extra["clicks"]); the done time is the page's mark, not the click. - Preview twins refresh the page every 250 ms (waiting for its load event) until it shows the change (
extra["reloads"]). - A change the page never shows fails the sample after 90 s with what each side did (
describe_miss): when granian saw it, when the last[timing]line came, whether the page reloaded, the app's last error line, and the page's last uncaught and console errors, e.g.granian saw it after 0.19 s, the last [timing] line came after 1.32 s, the page did not reload, the app's last error line: Error: No module update found for route routes/.$._index, …. So a failure says whether the watcher, the compile, vite or the page dropped it. - Hops per sample in
extra["hops"], in seconds since the edit:watcher_seen_s(granian'sChanges detectedline, raw line inextra["watcher_line"]),compile_done_s(the last[timing]line after it; the app runs with--loglevel debug) anddom_updated_s(the page's mark). Log line times areperf_counter()sinceapp.t0; the edit'stime_ns()maps onto them through the anchor.
Verification
All runs: this container (4-core Intel Xeon VM, Python 3.14.7), headless shell Chromium 141.0.7390.37, --no-save. HEAD is the workspace reflex 0.9.12.post18.dev0+8e72b14be with granian 2.8.1; 0.8.23 is PR-2's --reflex 0.8.23 venv with granian 2.8.3. The hmr.*, page load, forced-reload, Ctrl-C and A/A runs used this PR's code before it was committed, so the subject reads workspace 7dcc8b6, dirty (the only uncommitted changes were under packages/reflex-bench). Two later changes only added facts to the miss message (the page's uncaught errors and the app's last error line); the 0.8.23 hmr.render.root rerun below shows them.
Environment note: the container ships Playwright's headless shell build 1194 under /opt/pw-browsers, while the workspace's Playwright 1.62 expects build 1234, and playwright install was off limits here. Every run and page test used a scratch PLAYWRIGHT_BROWSERS_PATH whose chromium_headless_shell-1234/chrome-headless-shell-linux64/chrome-headless-shell is a symlink to the 1194 binary.
reflex-bench run 'browser.*.ready' --runs 5
Median [IQR] in seconds since the spawn; the gaps are medians of the per-sample differences.
HEAD: reflex 0.9.12.post18.dev0+8e72b14be
| benchmark | status | n | process_ready | http_ready | interactive_ready | http − process | interactive − http | fcp | nav_to_interactive |
|---|---|---|---|---|---|---|---|---|---|
browser.dev.ready | ok | 5 | 1.992 [1.978–2.022] | 2.536 [2.488–2.552] | 3.662 [3.600–3.730] | 0.531 | 1.153 | 3.688 [3.620–3.735] | 1.089 [1.086–1.125] |
browser.preview.ready | ok | 5 | 4.199 [4.141–4.237] | 4.209 [4.152–4.247] | 4.419 [4.398–4.477] | 0.010 | 0.230 | 4.427 [4.384–4.474] | 0.183 [0.169–0.190] |
browser.prod.ready | ok | 5 | 4.318 [4.287–4.364] | 4.329 [4.299–4.375] | 4.531 [4.510–4.595] | 0.011 | 0.212 | 4.457 [4.442–4.536] | 0.175 [0.172–0.179] |
0.8.23:
| benchmark | status | n | process_ready | http_ready | interactive_ready | http − process | interactive − http | fcp | nav_to_interactive |
|---|---|---|---|---|---|---|---|---|---|
browser.dev.ready | ok | 5 | 2.352 [2.319–2.405] | 2.951 [2.935–2.997] | 3.884 [3.854–3.895] | 0.616 | 0.899 | 3.880 [3.865–3.918] | 0.852 [0.845–0.881] |
browser.preview.ready | unsupported | requires reflex >= 0.9.8 (subject has 0.8.23) | |||||||
browser.prod.ready | ok | 5 | 7.981 [7.915–8.003] | 7.991 [7.924–8.014] | 8.226 [8.133–8.231] | 0.010 | 0.226 | 8.155 [8.059–8.155] | 0.179 [0.170–0.190] |
HEAD output
reflex-bench 0.0.0.post60.dev0+8e72b14be · reflex 0.9.12.post18.dev0+8e72b14be (workspace 7dcc8b6) · py 3.14.7
machine: linux-x86_64 · Intel Xeon · 4 cores · vm ⚠ · load 0.3
policy: runs 5 (fixed), warmup per benchmark, timeout per benchmark, α=0.01 (Holm), threshold 3 %, CI 95 %, bootstrap 10000, seed 2138097570, fail-on never
browser.dev.ready median ± 95 % CI range n
process_ready 1.992 s (need ≥ 6 samples) 1.977 s … 2.029 s 5
http_ready 2.536 s (need ≥ 6 samples) 2.447 s … 2.656 s 5
interactive_ready 3.662 s (need ≥ 6 samples) 3.581 s … 3.830 s 5
nav_to_interactive 1.089 s (need ≥ 6 samples) 1.058 s … 1.139 s 5
fcp 3.688 s (need ≥ 6 samples) 3.603 s … 3.833 s 5
browser.preview.ready
process_ready 4.199 s (need ≥ 6 samples) 4.132 s … 4.301 s 5
http_ready 4.209 s (need ≥ 6 samples) 4.143 s … 4.310 s 5
interactive_ready 4.419 s (need ≥ 6 samples) 4.378 s … 4.512 s 5
nav_to_interactive 183.0 ms (need ≥ 6 samples) 163.2 ms … 208.1 ms 5
fcp 4.427 s (need ≥ 6 samples) 4.378 s … 4.517 s 5
browser.prod.ready
process_ready 4.318 s (need ≥ 6 samples) 4.278 s … 4.463 s 5
http_ready 4.329 s (need ≥ 6 samples) 4.287 s … 4.473 s 5
interactive_ready 4.531 s (need ≥ 6 samples) 4.499 s … 4.740 s 5
nav_to_interactive 174.7 ms (need ≥ 6 samples) 166.1 ms … 207.1 ms 5
⚠ 1 severe outlier (sample 0: +19 %). Kept.
fcp 4.457 s (need ≥ 6 samples) 4.429 s … 4.668 s 5
0.8.23 output (--reflex 0.8.23)
reflex-bench 0.0.0.post60.dev0+8e72b14be · reflex 0.8.23 (0.8.23) · py 3.14.7
machine: linux-x86_64 · Intel Xeon · 4 cores · vm ⚠ · load 1.46 ⚠
policy: runs 5 (fixed), warmup per benchmark, timeout per benchmark, α=0.01 (Holm), threshold 3 %, CI 95 %, bootstrap 10000, seed 717330798, fail-on never
browser.dev.ready median ± 95 % CI range n
process_ready 2.352 s (need ≥ 6 samples) 2.294 s … 2.446 s 5
http_ready 2.951 s (need ≥ 6 samples) 2.915 s … 3.259 s 5
⚠ 1 severe outlier (sample 0: +10 %). Kept.
interactive_ready 3.884 s (need ≥ 6 samples) 3.850 s … 4.122 s 5
⚠ 1 severe outlier (sample 0: +6 %). Kept.
nav_to_interactive 851.6 ms (need ≥ 6 samples) 804.2 ms … 883.8 ms 5
fcp 3.880 s (need ≥ 6 samples) 3.851 s … 4.149 s 5
⚠ 1 severe outlier (sample 0: +7 %). Kept.
browser.preview.ready
– unsupported: requires reflex >= 0.9.8 (subject has 0.8.23)
browser.prod.ready
process_ready 7.981 s (need ≥ 6 samples) 7.892 s … 8.119 s 5
http_ready 7.991 s (need ≥ 6 samples) 7.901 s … 8.130 s 5
interactive_ready 8.226 s (need ≥ 6 samples) 8.127 s … 8.377 s 5
nav_to_interactive 179.0 ms (need ≥ 6 samples) 166.5 ms … 196.0 ms 5
fcp 8.155 s (need ≥ 6 samples) 8.056 s … 8.307 s 5
3 benchmarks: 2 ok · 1 unsupported
reflex-bench run 'hmr.*' --runs 10
Latency median [IQR] (min–max) in seconds over 10 timed edits after 3 warm-up edits, full_reloads summed over the 10 samples, and the median clicks or refreshes per sample:
| Benchmark | HEAD | 0.8.23 |
|---|---|---|
hmr.render.leaf | 1.438 [1.420–1.456] (1.294–1.514); full_reloads 0 | 1.520 [1.512–1.531] (1.459–1.588); full_reloads 0 |
hmr.render.leaf.preview | 3.781 [3.717–3.834] (3.671–3.856); full_reloads 0; 2 reloads | unsupported |
hmr.render.root | 1.397 [1.376–1.433] (1.367–1.497); full_reloads 0 | failed (below) |
hmr.render.root.preview | 3.711 [3.665–3.744] (3.606–3.846); full_reloads 0; 2 reloads | unsupported |
hmr.handler | 1.184 [1.176–1.232] (1.153–1.307); full_reloads 0; 5 clicks | 1.379 [1.337–1.449] (1.248–1.570); full_reloads 0; 6 clicks |
hmr.handler.preview | 3.584 [3.524–3.620] (3.500–3.715); full_reloads 0; 14.5 clicks | unsupported |
hmr.css | failed (below) | 1.465 [1.436–1.490] (1.391–1.550); full_reloads 0 |
hmr.css.preview | 3.713 [3.666–3.792] (3.619–3.804); full_reloads 0; 2 reloads | unsupported |
hmr.asset | failed (below) | failed (below) |
hmr.asset.preview | 3.770 [3.711–3.816] (3.496–3.852); full_reloads 0; 2 reloads | unsupported |
hmr.reconnect | 2.895 [2.776–2.958] (2.430–3.133); full_reloads 0; 12 clicks | 2.851 [2.789–2.893] (2.539–3.106); full_reloads 0; 12 clicks |
hmr.reconnect.preview | 3.547 [3.385–3.633] (3.190–3.924); full_reloads 0; 14 clicks | unsupported |
hmr.watcher | 0.167 [0.121–0.177] (0.103–0.193); full_reloads 0 | 0.127 [0.125–0.130] (0.101–0.143); full_reloads 0 |
No variant full-reloaded on either version: full_reloads is 0 in every sample of every variant, and no sample saw its __BENCH_ALIVE tag replaced. The failures are changes the dev page never showed at all, neither by a hot update nor by a reload; each error now says which side dropped the change:
HEAD hmr.asset: TimeoutError: the page did not show the edit (naturalWidth of img[alt="Playground logo"]) within 90 s: granian saw it after 0.11 s, the last [timing] line came after 1.14 s, the page did not reload
HEAD hmr.css: TimeoutError: the page did not show the edit (style:font-size of .bench-hooks) within 90 s: granian saw it after 0.17 s, the last [timing] line came after 1.18 s, the page did not reload
0.8.23 hmr.asset: TimeoutError: the page did not show the edit (naturalWidth of img[alt="Playground logo"]) within 90 s: granian saw it after 0.14 s, the last [timing] line came after 1.29 s, the page did not reload, the page's last console error: WebSocket connection to 'ws://localhost:52899/_event/?token=f26cc754-4f1c-400f-b547-e7b10965d9b8&EIO=4&transport=websocket' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
0.8.23 hmr.render.root: TimeoutError: the page did not show the edit (text of #bench-marker-root) within 90 s: granian saw it after 0.16 s, the last [timing] line came after 1.23 s, the page did not reload, the page's last console error: WebSocket connection to 'ws://localhost:36251/_event/?token=bd5ee110-d9d3-4530-ecab-d8facc32d47b&EIO=4&transport=websocket' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
What the page did, from diag_edit.py (a scratch script: one edit on a running dev app, printing the vite messages, navigations and page errors, and the app's log lines after the edit):
-
hmr.css, HEAD dev: the new stylesheet is fetched but never applied. vite sends a CSS update and the page fetches the new__reflex_global_styles.css, but the computed size stays at12px, and 3 s later Chrome warns that the file was preloaded and never used. No reload follows. On 0.8.23 the same update applies after 1.50 s (hmr.cssmedian 1.465 s). This looks like a Reflex HEAD dev-mode bug.HEAD dev css (seconds since the edit; page events, then the app's log) before: 12px mark: None latency: None after: 12px alive: True 1.145 request http://localhost:41667/styles/__reflex_global_styles.css?t=1790198287830 1.437 console.debug [vite] css hot updated: /styles/__reflex_global_styles.css 4.435 console.warning The resource http://localhost:41667/styles/__reflex_global_styles.css?t=1790198287830 was preloaded using link preload but not used within a few seconds from th… [INFO] Changes detected, reloading workers.. [INFO] Added: …/pg/assets/playground.css Debug: [timing] Compile pages: 0.06s Debug: [timing] Copy assets: 0.00s Debug: 9:18:07 PM [vite] (client) hmr update /styles/__reflex_global_styles.css?direct 0.8.23 dev css before: 12px mark: {'perf': 2414.100000000559, 'epoch': 1790198314188} latency: 1.5015151500701904 after: 27px alive: True 1.52 console.debug [vite] css hot updated: /styles/__reflex_global_styles.css -
hmr.asset, both versions: the page never reloads the logo. granian seesassets/logo.svg, reflex copies it into.web/public, and vite reports only a CSS update of the global styles. The page neither reloads nor fetches the image again, sonaturalWidthstays 150 (HTTP cache off). vite does not full-reload for public-dir changes here, so the prompt's expected reload never came. Preview picks the new file up on a refresh (hmr.asset.preview, 3.770 s).HEAD dev asset mark: None latency: None after: 150 alive: True 1.415 console.debug [vite] css hot updated: /styles/__reflex_global_styles.css [INFO] Changes detected, reloading workers.. [INFO] Added: …/pg/assets/logo.svg Debug: 9:18:41 PM [vite] (client) hmr update /styles/__reflex_global_styles.css?direct 0.8.23 dev asset mark: None latency: None after: 150 alive: True 1.538 console.debug [vite] css hot updated: /styles/__reflex_global_styles.css [INFO] Added: …/pg0823/assets/logo.svg Debug: 9:19:07 PM [vite] (client) hmr update /styles/__reflex_global_styles.css?direct -
hmr.render.root, 0.8.23 dev: React Router's HMR runtime throws. An edit oflayout.py(imported by every page) reaches vite as an update of_index.jsx, and React Router's HMR runtime throws on a route the page never loaded (routes/.$._index). The update never applies. This is the issue HEAD's vite config patches (patchReactRouterHmrRuntime: "Its HMR runtime throws on those entries before clearing the queue, which blocks every later update until the browser is reloaded"), and it is why the same benchmark passes on HEAD (1.397 s):0.8.23 dev root mark: None latency: None after: m-initial-root alive: True 1.62 console.debug [vite] hot updated: /app/routes/_index.jsx Debug: 9:19:41 PM [vite] (client) hmr update /app/routes/_index.jsx Error: No module update found for route routes/.$._index at http://localhost:37977/@id/__x00__virtual:react-router/hmr-runtime:442:25 HEAD dev root mark: {'perf': 2888.899999999441, 'epoch': 1790198374438} latency: 1.4780621528625488 after: m-diagnose alive: TrueThe benchmark's own error now names it (
hmr.render.root --reflex 0.8.23 --runs 3, after the app-error fact was added):✗ failed: TimeoutError: the page did not show the edit (text of #bench-marker-root) within 90 s: granian saw it after 0.19 s, the last [timing] line came after 1.32 s, the page did not reload, the app's last error line: Error: No module update found for route routes/.$._index, the page's last console error: WebSocket connection to 'ws://localhost:50111/_event/?token=…&EIO=4&transport=websocket' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
Per-edit hops of hmr.render.leaf, in seconds since the edit (raw watcher line: [INFO] Changes detected, reloading workers.. on both granian versions):
HEAD: watcher_seen compile_done dom_updated
0.174 1.243 1.460
0.185 1.188 1.462
0.113 1.075 1.294
0.155 1.207 1.417
0.112 1.175 1.374
0.119 1.223 1.426
0.151 1.271 1.514
0.132 1.201 1.444
0.177 1.227 1.438
0.190 1.208 1.438
0.8.23: watcher_seen compile_done dom_updated
0.133 1.230 1.459
0.122 1.276 1.514
0.131 1.296 1.512
0.138 1.291 1.543
0.131 1.272 1.533
0.134 1.272 1.514
0.138 1.289 1.526
0.133 1.343 1.588
0.124 1.223 1.490
0.135 1.294 1.527
The watcher sees the edit after 0.10–0.19 s, the recompile ends ~1.2 s after the edit, and the page shows it ~0.2 s later. Nothing points at a Reflex-internal HMR hook (window.__reflexHmrLatencyCb) being needed yet: the compile dominates, and the gap from the last [timing] line to the DOM (vite transform, HMR message, React refresh) stays at 0.20–0.27 s.
HEAD output
reflex-bench 0.0.0.post60.dev0+8e72b14be · reflex 0.9.12.post18.dev0+8e72b14be (workspace 7dcc8b6, dirty) · py 3.14.7
machine: linux-x86_64 · Intel Xeon · 4 cores · vm ⚠ · load 0.35
policy: runs 10 (fixed), warmup per benchmark, timeout per benchmark, α=0.01 (Holm), threshold 3 %, CI 95 %, bootstrap 10000, seed 1043518702, fail-on never
hmr.asset[app=playground] median ± 95 % CI range n
✗ failed: TimeoutError: the page did not show the edit (naturalWidth of img[alt="Playground logo"]) within 90 s: granian saw it after 0.11 s, the last [timing] line came after 1.14 s, the page did not reload
hmr.asset.preview[app=playground]
latency 3.770 s ± 3.1 % 3.496 s … 3.852 s 10
full_reloads 0 0 … 0 10
hmr.css[app=playground]
✗ failed: TimeoutError: the page did not show the edit (style:font-size of .bench-hooks) within 90 s: granian saw it after 0.17 s, the last [timing] line came after 1.18 s, the page did not reload
hmr.css.preview[app=playground]
latency 3.713 s ± 2.4 % 3.619 s … 3.804 s 10
full_reloads 0 0 … 0 10
hmr.handler[app=playground]
latency 1.184 s ± 5.4 % 1.153 s … 1.307 s 10
full_reloads 0 0 … 0 10
hmr.handler.preview[app=playground]
latency 3.584 s ± 2.4 % 3.500 s … 3.715 s 10
full_reloads 0 0 … 0 10
hmr.reconnect[app=playground]
latency 2.895 s ± 9.3 % 2.430 s … 3.133 s 10
full_reloads 0 0 … 0 10
hmr.reconnect.preview[app=playground]
latency 3.547 s ± 10.0 % 3.190 s … 3.924 s 10
full_reloads 0 0 … 0 10
hmr.render.leaf[app=playground]
latency 1.438 s ± 4.4 % 1.294 s … 1.514 s 10
⚠ 1 severe outlier (sample 5: -10 %). Kept.
full_reloads 0 0 … 0 10
hmr.render.leaf.preview[app=playground]
latency 3.781 s ± 2.2 % 3.671 s … 3.856 s 10
full_reloads 0 0 … 0 10
hmr.render.root[app=playground]
latency 1.397 s ± 5.2 % 1.367 s … 1.497 s 10
full_reloads 0 0 … 0 10
hmr.render.root.preview[app=playground]
latency 3.711 s ± 2.0 % 3.606 s … 3.846 s 10
full_reloads 0 0 … 0 10
hmr.watcher[app=playground]
latency 167.2 ms ± 32 % 103.3 ms … 193.3 ms 10
⚠ high variance: CV 21 % (warns at 10 %)
full_reloads 0 0 … 0 10
13 benchmarks: 2 failed · 11 ok
0.8.23 output
reflex-bench 0.0.0.post60.dev0+8e72b14be · reflex 0.8.23 (0.8.23) · py 3.14.7
machine: linux-x86_64 · Intel Xeon · 4 cores · vm ⚠ · load 2.07 ⚠
policy: runs 10 (fixed), warmup per benchmark, timeout per benchmark, α=0.01 (Holm), threshold 3 %, CI 95 %, bootstrap 10000, seed 3071680528, fail-on never
hmr.asset[app=playground] median ± 95 % CI range n
✗ failed: TimeoutError: the page did not show the edit (naturalWidth of img[alt="Playground logo"]) within 90 s: granian saw it after 0.14 s, the last [timing] line came after 1.29 s, the page did not reload, the page's last console error: WebSocket connection to 'ws://localhost:52899/_event/?token=f26cc754-4f1c-400f-b547-e7b10965d9b8&EIO=4&transport=websocket' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
hmr.asset.preview[app=playground]
– unsupported: requires reflex >= 0.9.8 (subject has 0.8.23)
hmr.css[app=playground]
latency 1.465 s ± 2.9 % 1.391 s … 1.550 s 10
full_reloads 0 0 … 0 10
hmr.css.preview[app=playground]
– unsupported: requires reflex >= 0.9.8 (subject has 0.8.23)
hmr.handler[app=playground]
latency 1.379 s ± 13 % 1.248 s … 1.570 s 10
full_reloads 0 0 … 0 10
hmr.handler.preview[app=playground]
– unsupported: requires reflex >= 0.9.8 (subject has 0.8.23)
hmr.reconnect[app=playground]
latency 2.851 s ± 4.3 % 2.539 s … 3.106 s 10
full_reloads 0 0 … 0 10
hmr.reconnect.preview[app=playground]
– unsupported: requires reflex >= 0.9.8 (subject has 0.8.23)
hmr.render.leaf[app=playground]
latency 1.520 s ± 2.0 % 1.459 s … 1.588 s 10
full_reloads 0 0 … 0 10
hmr.render.leaf.preview[app=playground]
– unsupported: requires reflex >= 0.9.8 (subject has 0.8.23)
hmr.render.root[app=playground]
✗ failed: TimeoutError: the page did not show the edit (text of #bench-marker-root) within 90 s: granian saw it after 0.16 s, the last [timing] line came after 1.23 s, the page did not reload, the page's last console error: WebSocket connection to 'ws://localhost:36251/_event/?token=bd5ee110-d9d3-4530-ecab-d8facc32d47b&EIO=4&transport=websocket' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
hmr.render.root.preview[app=playground]
– unsupported: requires reflex >= 0.9.8 (subject has 0.8.23)
hmr.watcher[app=playground]
latency 127.5 ms ± 3.8 % 101.1 ms … 143.1 ms 10
⚠ 1 severe outlier (sample 6: -21 %). Kept.
full_reloads 0 0 … 0 10
13 benchmarks: 2 failed · 6 unsupported · 5 ok
hmr.watcher against reload_tick
Both versions run granian's reloader with reload_tick=100 (watchfiles' step): watchfiles yields a change once a 100 ms step passes with no new change, so the reload line lands 1–2 ticks after the edit. Measured: HEAD 0.167 s median (0.103–0.193, 10 edits; a second run of 20 edits: 0.160 s, 0.107–0.195), 0.8.23 0.127 s (0.101–0.143).
Forced full reload
A fresh REFLEX_BENCH_HOME with VITE_FORCE_FULL_RELOAD=true, so the staged app's first compile writes vite's fullReload() plugin (every change becomes {type: "full-reload"}):
reflex-bench 0.0.0.post60.dev0+8e72b14be · reflex 0.9.12.post18.dev0+8e72b14be (workspace 7dcc8b6, dirty) · py 3.14.7
machine: linux-x86_64 · Intel Xeon · 4 cores · vm ⚠ · load 1.55 ⚠
policy: runs 2 (fixed), warmup 0, timeout per benchmark, α=0.01 (Holm), threshold 3 %, CI 95 %, bootstrap 10000, seed 332689890, fail-on never
hmr.css[app=playground] median ± 95 % CI range n
latency 1.609 s (need ≥ 6 samples) 1.582 s … 1.637 s 2
full_reloads 1 (need ≥ 6 samples) 1 … 1 2
hmr.render.leaf[app=playground]
✗ failed: FullReloadError: all 3 tries reloaded the page instead of updating it
2 benchmarks: 1 ok · 1 failed
$ grep -H 'concat(\[fullReload()\])' $REFLEX_BENCH_HOME/cache/*/*/*/app/A/.web/vite.config.js
$SCRATCH/home-forced/cache/7dcc8b61549ffc10935a9049a3e91788bd140046-dirty/hmr.css/f69c7cc79630/app/A/.web/vite.config.js: ].concat([fullReload()]),
$SCRATCH/home-forced/cache/7dcc8b61549ffc10935a9049a3e91788bd140046-dirty/hmr.render.leaf/f69c7cc79630/app/A/.web/vite.config.js: ].concat([fullReload()]),
hmr.render.leaf retried with new markers and failed with FullReloadError after 3 reloads, so no reload was timed; hmr.css (a change that may show through a reload) timed the reload and counted it in full_reloads.
reflex-bench run browser.prod.pageload --runs 10
HEAD: reflex 0.9.12.post18.dev0+8e72b14be
| benchmark | status | n | fcp | lcp | interactive | tbt | ws_bytes | transfer_bytes | long tasks (median) |
|---|---|---|---|---|---|---|---|---|---|
browser.prod.pageload[cpu=1] | ok | 10 | 0.098 [0.089–0.104] | 0.098 [0.089–0.104] | 0.164 [0.154–0.169] | 0.000 [0.000–0.000] | 2,854 [2,854–2,854] | 315,405 [315,405–315,405] | 0 |
browser.prod.pageload[cpu=4] | ok | 10 | 0.296 [0.292–0.310] | 0.296 [0.292–0.310] | 0.665 [0.648–0.685] | 0.042 [0.036–0.047] | 2,854 [2,854–2,854] | 315,402 [315,402–315,402] | 2 |
0.8.23:
| benchmark | status | n | fcp | lcp | interactive | tbt | ws_bytes | transfer_bytes | long tasks (median) |
|---|---|---|---|---|---|---|---|---|---|
browser.prod.pageload[cpu=1] | ok | 10 | 0.102 [0.096–0.104] | 0.102 [0.096–0.104] | 0.164 [0.158–0.173] | 0.000 [0.000–0.000] | 2,785 [2,785–2,785] | 1,659,470 [1,659,470–1,659,470] | 0 |
browser.prod.pageload[cpu=4] | ok | 10 | 0.282 [0.280–0.302] | 0.282 [0.280–0.302] | 0.672 [0.657–0.682] | 0.042 [0.037–0.046] | 2,785 [2,785–2,785] | 1,659,472 [1,659,472–1,659,472] | 2 |
lcp, interactive and tbt rise with cpu=4 as they should. ws_bytes and transfer_bytes do not change, and should not: a CPU slowdown changes when bytes arrive, not how many (the prompt expected them to differ; see deviation 16). Across versions, HEAD's page transfers 315 kB against 0.8.23's 1.66 MB (responseBodySize: encoded bytes as sent).
HEAD output
reflex-bench 0.0.0.post60.dev0+8e72b14be · reflex 0.9.12.post18.dev0+8e72b14be (workspace 7dcc8b6, dirty) · py 3.14.7
machine: linux-x86_64 · Intel Xeon · 4 cores · vm ⚠ · load 0.44
policy: runs 10 (fixed), warmup per benchmark, timeout per benchmark, α=0.01 (Holm), threshold 3 %, CI 95 %, bootstrap 10000, seed 2955440137, fail-on never
browser.prod.pageload[cpu=1] median ± 95 % CI range n
fcp 98.0 ms ± 18 % 76.0 ms … 132.0 ms 10
⚠ high variance: CV 16 % (warns at 10 %)
lcp 98.0 ms ± 18 % 76.0 ms … 132.0 ms 10
⚠ high variance: CV 16 % (warns at 10 %)
interactive 163.8 ms ± 9.0 % 136.7 ms … 200.0 ms 10
⚠ high variance: CV 10 % (warns at 10 %)
tbt 0.000 s 0.000 s … 0.000 s 10
ws_bytes 2.854 kB ± 0.0 % 2.854 kB … 2.854 kB 10
transfer_bytes 315.4 kB ± 0.0 % 315.4 kB … 315.4 kB 10
browser.prod.pageload[cpu=4]
fcp 296.0 ms ± 6.8 % 224.0 ms … 348.0 ms 10
⚠ high variance: CV 11 % (warns at 10 %)
⚠ 1 severe outlier (sample 5: -24 %). Kept.
lcp 296.0 ms ± 6.8 % 224.0 ms … 348.0 ms 10
⚠ high variance: CV 11 % (warns at 10 %)
⚠ 1 severe outlier (sample 5: -24 %). Kept.
interactive 665.2 ms ± 7.3 % 619.1 ms … 861.2 ms 10
⚠ high variance: CV 10 % (warns at 10 %)
⚠ 1 severe outlier (sample 7: +29 %). Kept.
tbt 42.50 ms ± 27 % 22.00 ms … 62.00 ms 10
⚠ high variance: CV 27 % (warns at 10 %)
ws_bytes 2.854 kB ± 0.0 % 2.854 kB … 2.854 kB 10
transfer_bytes 315.4 kB ± 0.0 % 315.4 kB … 315.4 kB 10
0.8.23 output
reflex-bench 0.0.0.post60.dev0+8e72b14be · reflex 0.8.23 (0.8.23) · py 3.14.7
machine: linux-x86_64 · Intel Xeon · 4 cores · vm ⚠ · load 0.48
policy: runs 10 (fixed), warmup per benchmark, timeout per benchmark, α=0.01 (Holm), threshold 3 %, CI 95 %, bootstrap 10000, seed 937322716, fail-on never
browser.prod.pageload[cpu=1] median ± 95 % CI range n
fcp 102.0 ms ± 9.8 % 88.0 ms … 116.0 ms 10
lcp 102.0 ms ± 9.8 % 88.0 ms … 116.0 ms 10
interactive 163.7 ms ± 6.3 % 151.5 ms … 180.9 ms 10
tbt 0.000 s 0.000 s … 0.000 s 10
ws_bytes 2.785 kB ± 0.0 % 2.785 kB … 2.785 kB 10
transfer_bytes 1.659 MB ± 0.0 % 1.659 MB … 1.659 MB 10
browser.prod.pageload[cpu=4]
fcp 282.0 ms ± 7.8 % 200.0 ms … 312.0 ms 10
⚠ high variance: CV 11 % (warns at 10 %)
⚠ 1 severe outlier (sample 8: -29 %). Kept.
lcp 282.0 ms ± 7.8 % 200.0 ms … 312.0 ms 10
⚠ high variance: CV 11 % (warns at 10 %)
⚠ 1 severe outlier (sample 8: -29 %). Kept.
interactive 672.3 ms ± 2.9 % 646.5 ms … 728.9 ms 10
tbt 42.50 ms ± 25 % 29.00 ms … 56.00 ms 10
⚠ high variance: CV 20 % (warns at 10 %)
ws_bytes 2.785 kB ± 0.0 % 2.785 kB … 2.785 kB 10
transfer_bytes 1.659 MB ± 0.0 % 1.659 MB … 1.659 MB 10
Leftover processes, Ctrl-C, examples/
After every run above, leftovers.py (a psutil scan for any process carrying REFLEX_BENCH_OWNER, a Playwright driver, a Chromium or headless shell, reflex, granian, react-router, vite or a multiprocessing child) printed leftover processes: 0, and git status --short examples/ printed nothing.
Ctrl-C during hmr.render.root: the script starts reflex-bench run hmr.render.root --runs 10 as a job (set -m: a background job of a script otherwise starts with SIGINT ignored), waits until the staged layout.py holds an m-<12 hex> edit, then sends SIGINT to the job's whole process group, as a terminal does:
staged: .reflex-bench/cache/7dcc8b61549ffc10935a9049a3e91788bd140046-dirty/hmr.render.root/f69c7cc79630/app/A/playground/layout.py
edit on disk at 21:13:53.503: ROOT_MARKER = "m-cd3ee416407c"
reflex-bench exit=130
interrupted
staged layout.py restored (identical to the checkout)
leftover processes: 0
git status examples/:
(end)
Cross-thread Playwright error and the clock anchor
$ cat crossthread.py
"""Call the sync Playwright API from a thread other than the one that created it."""
import threading
import traceback
from playwright.sync_api import sync_playwright
pw = sync_playwright().start()
browser = pw.chromium.launch()
page = browser.new_page()
page.set_content("<title>made on the main thread</title>")
print("main thread:", page.title())
def other():
try:
print("second thread:", page.title())
except BaseException as exc:
print("second thread raised", type(exc).__module__ + "." + type(exc).__qualname__)
print("message:", exc)
thread = threading.Thread(target=other)
thread.start()
thread.join()
browser.close()
pw.stop()
$ uv run python crossthread.py
main thread: made on the main thread
second thread raised greenlet.error
message: Cannot switch to a different thread
Current: <greenlet.greenlet object at 0x7f2501fe2240 (otid=0x7f24fc000ca0) current active started main>
Expected: <greenlet.greenlet object at 0x7f2502d27c80 (otid=0x25d72210) suspended active started main>
Exception in callback SyncBase._sync.<locals>.<lambda>() at /home/user/reflex/.venv/lib/python3.14/site-packages/playwright/_impl/_sync_base.py:111
handle: <Handle SyncBase._sync.<locals>.<lambda>() at /home/user/reflex/.venv/lib/python3.14/site-packages/playwright/_impl/_sync_base.py:111>
Traceback (most recent call last):
File "/root/.local/share/uv/python/cpython-3.14.7-linux-x86_64-gnu/lib/python3.14/asyncio/events.py", line 94, in _run
self._context.run(self._callback, *self._args)
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/user/reflex/.venv/lib/python3.14/site-packages/playwright/_impl/_sync_base.py", line 111, in <lambda>
task.add_done_callback(lambda _: g_self.switch())
~~~~~~~~~~~~~^^
greenlet.error: cannot switch to a different thread (which happens to have exited)
Anchor spread (extra["anchor_spread_s"], every sample of the runs above): max 0.27 µs, median 0.16 µs over 279 samples.
A/A with per-arm staged apps
reflex-bench ab --head workspace --aa hmr.render.leaf --rounds 3 --warmup 1: both arms' dev servers ran at once, from <cache>/app/A and <cache>/app/B:
reflex-bench 0.0.0.post60.dev0+8e72b14be · A: reflex 0.9.12.post18.dev0+8e72b14be (workspace 7dcc8b6, dirty) · py 3.14.7
machine: linux-x86_64 · Intel Xeon · 4 cores · vm ⚠ · load 1.36 ⚠
policy: runs 3 (fixed), warmup 1, timeout per benchmark, α=0.01 (Holm), threshold 3 %, CI 95 %, bootstrap 10000, seed 501650239, fail-on never
hmr.render.leaf[app=playground] median ± 95 % CI range n
latency [A] 1.423 s (need ≥ 6 samples) 1.335 s … 1.569 s 3
latency [B] 1.465 s (need ≥ 6 samples) 1.454 s … 1.601 s 3
full_reloads [A] 0 (need ≥ 6 samples) 0 … 0 3
full_reloads [B] 0 (need ≥ 6 samples) 0 … 0 3
reflex-bench compare A=workspace B=workspace α=0.01 (Holm, 2 metrics) threshold=3 %
base head
hmr.render.leaf[app=playground] latency 1.423 s 1.465 s +3.0 % p=0.80 n=3/3 ? inconclusive (~6 runs/side needed)
full_reloads 0 0 +0 (absolute) p=1.00 n=3/3 ? inconclusive (~6 runs/side needed)
geomean (time) +3.0 %
0 regressed · 0 improved · 2 inconclusive · 0 unchanged
Version differences (section 2.5)
-
Granian workers (
diag_queue.py, both versions): the supervisor is the root,python -m reflex run --env dev …(granian's supervisor runs in reflex's main thread), and the worker ispython -c "from multiprocessing.spawn import spawn_main; spawn_main(…)" …, listening on the backend port. With Python 3.14 the tree also holds multiprocessing's resource tracker and forkserver, which is why the worker is found by its socket (deviation 2). Kill + SIGHUP, as logged by the app:HEAD 4.783 [ERROR] Unexpected exit from worker-1 4.815 [INFO] HUP signal received, gracefully respawning workers.. 4.816 [INFO] Spawning worker-1 with PID: 29016 5.601 [INFO] Started worker-1 0.8.23 5.074 [ERROR] Unexpected exit from worker-1 5.153 [INFO] HUP signal received, gracefully respawning workers.. 5.974 [INFO] Started worker-1 -
Queued clicks across a reconnect: on both versions, one click on
#increment50 ms after the kill (backend down) reached the new worker. The count went 0 → 1, recorded 1.28 s after the kill, without further clicks (count 0 -> 1 mark after 1.277 son HEAD,1.28 son 0.8.23). The benchmark still clicks every 250 ms, which covers either behaviour. -
0.8.23's
reloadsocket event did not fire after a worker kill:reload_eventsis 0 in all 10hmr.reconnectsamples on both versions (0.8.23 uses the disk state manager in dev, so the new worker finds the state), anddiag_queue.pysaw onlyeventframes. -
.webrewrite: 0.8.23'sreflex/compiler/utils.py:613write_filealso skips unchanged content (if path.exists() and path.read_text(encoding="utf-8") == code: return), like HEAD'sreflex/utils/path_ops.py:19. On both versions vite sees only the changed page module (hmr update /app/routes/_index.jsxabove). -
Watcher line:
[INFO] Changes detected, reloading workers..from granian 2.8.1 (HEAD) and 2.8.3 (0.8.23's venv,subject.extra["granian"]), followed by one[INFO] Added: <path>line per change (the atomicos.replaceshows up asAdded).WATCHERmatchesChanges detectedonly, and the raw line is stored inextra["watcher_line"]. -
Tier 3:
#bench-hydratedappears on both versions, in dev, preview (HEAD) and prod (tables above).
Tests and repo checks
On the final commit, rebased onto d8391fa2d:
uv run ruff check .: all checks passed.uv run ruff format --check .: 1638 files already formatted.uv run pyright reflex tests packages/reflex-bench/src: 0 errors.uv run pytest tests/units/reflex_bench -q(browser path as above): 564 passed, 4 skipped (all opt-in: this PR's two real-app modules, the lower PRs' selftest app and network tests). The page tests run a real headless Chromium againstfixtures/html/bench_page.html. The regression test for the lost-mark bug fails on the previousbench_page.js(assert None == {'perf': 216.70000000018626, 'epoch': 1790195826887}) and passes now.uv run pytest tests/units --cov --no-cov-on-fail --cov-report=: 10355 passed, 24 skipped in 4 min 18 s; total coverage 80.78 % (the gate is 72 %).- Opt-in real-app tests:
REFLEX_BENCH_APP_TESTS=1 uv run pytest tests/units/reflex_bench/suites/test_browser_hmr_app.py(workspace:browser.dev.readyandhmr.render.leafend to end) passed in 35.1 s, andREFLEX_BENCH_NETWORK_TESTS=1 uv run pytest tests/units/reflex_bench/suites/test_browser_hmr_app_0823.py(the same through--reflex 0.8.23) passed in 40.4 s. Both check tier order,interactive_ready > http_ready, one hot reload latency,full_reloads == 0and that no owned process is left. uv run pre-commit run --files <the 22 files of this PR>: every hook passed (biome reformatted one line ofbench_page.jsfirst).uvx --from uv==0.12.5 uv lock --check(CI's uv):Resolved 215 packages.
Findings for Reflex
Things the benchmarks surfaced, worth their own issues (none is fixed here):
- HEAD dev: stylesheet changes under
assets/never show. vite's CSS update fetches the new__reflex_global_styles.cssas a preload that is never applied, and Chrome warns that it went unused (hmr.cssfails on HEAD; 0.8.23 applies the same change in 1.465 s). - Dev, both versions: a changed public asset never reaches the page. The logo is replaced in
.web/public, but the page neither reloads nor refetches it (hmr.assetfails on both; preview shows it after a refresh, 3.770 s). - 0.8.23 dev: editing a module every page imports breaks HMR. React Router's HMR runtime throws
No module update found for route routes/.$._index. HEAD fixed this withpatchReactRouterHmrRuntime(hmr.render.root1.397 s on HEAD). - One missed leaf edit on HEAD. In the first HEAD run, the 9th edit of the
hmr.watcherinstance never showed within 90 s. It did not happen again in ~200 further leaf edits (the stress script and three more runs). If it recurs, the error now says which side dropped it. - Only the first reconnect is fast. In every
hmr.reconnectinstance, on both versions, the first kill (a warm-up) came back in 0.89 s (HEAD) and 1.07 s (0.8.23), with the respawned worker's last[timing]line ~0.87 s after the kill. Every later kill took 2.4–3.2 s, with that line at 2.4–2.8 s. The 3 warm-up samples absorb the first one.diag_queue.py's single kill in a fresh app came back in 1.28 s. Something makes later respawns compile slower; not investigated here. - Prod page weight:
/transfers 315 kB on HEAD and 1.66 MB on 0.8.23 (encoded bytes as sent).
Deviations from the prompt, with reasons
hmr.reconnectkills the worker and then sends SIGHUP to granian's supervisor. SIGKILL alone never recovers: both versions run granian's dev reloader withreload_ignore_worker_failure=True, and_watcherreturns without a respawn on an unexpected worker exit (granian/server/common.py:58-65, 2.8.1 and 2.8.3). Measured on HEAD: after the SIGKILL the log says[ERROR] Unexpected exit from worker-1and the port refuses connections for the whole 10 s observed (HEAD'sParentBoundGranianreleases the socket). SIGHUP alone is no crash either: granian respawns gracefully and the old worker keeps serving forrespawn_interval(3.5 s), so the page never disconnects. SIGKILL + SIGHUP gives the crash plus the respawn granian skips (backend back in ~1 s on HEAD).latencystill runs from the kill.- The worker is found by its listening socket, not as "the Python child that is not the root". On Python 3.14 the dev tree has three Python children: multiprocessing's resource tracker, the forkserver (3.14's default start method) and the granian worker (
python -c "from multiprocessing.spawn import spawn_main; …" --multiprocessing-fork).granian_processes(app)returns the root (the supervisor runs inreflex run's main thread on both versions) and the non-root process listening on the backend port (HEAD: the supervisor holds the socket and the worker inherits it; 0.8.23's plain granian: each worker binds withSO_REUSEPORT). - A style or asset change a dev page never shows fails the sample, instead of the prompt's expected vite full reload (which does not happen, see the results). The harness refreshes pages only in preview mode, where a refresh is the documented way to see a change.
- Preview twins reload the page themselves every 250 ms (waiting for its load event) when the change needs a new page: preview has no live reload ("a manual browser refresh shows changes",
reflex/reflex.py_run_preview). Theirfull_reloadsis 0 by definition andextra["reloads"]counts the harness's refreshes.hmr.watcherhas no preview twin: the watcher is granian's, identical in both modes. - Staged app per arm (
<cache>/app/<arm>instead of<cache>/app): in an A/A run both arms share one cache directory, and the hmr benchmarks' dev servers (and pageload's prod server) would otherwise run in, and hot reload, one directory. stage_playgroundalso skips.states,reflex.lock,uv.lockand*.db(the prompt lists.venv,.web,__pycache__): a localreflex runinexamples/playgroundleaves areflex.lock/that would pin the staged app's frontend packages. It keeps the destination's own.webandreflex.lock, so restaging (every invocation runssetup_cacheonce) compiles warm.playground_dir()usesparents[5], notparents[4]: the module isreflex_bench/fixtures/__init__.py, one level deeper than afixtures.pywould be.- Page load reporting: PR-1's report does not trim outliers (it reports the median with an order-statistic CI and counts Tukey outliers, "Outliers are never removed"), so the docstring says to read the median and its CI over at least 6 runs; no trimming was added.
FullReloadError's entry error readsFullReloadError: all 3 tries reloaded the page instead of updating it: the scheduler prefixes every error with the exception type, so it cannot start withfull_reload:without changing PR-1.new_page()returns aTab(the PlaywrightPageistab.page) so a page's counters (page errors, console, websocket bytes, responses) and its CDP session travel with it.owned_processes()includes the descendants of token carriers, since Chromium's helpers have an empty environment;_ProcessTree.members()uses it for its scan (PR-3 asked to reuse, not copy, its owner scan).transfer_bytessumsrequest.sizes()["responseBodySize"](the encoded body size Playwright reports) instead ofcontent-length, which is missing on chunked responses.- The owner thread is compared by
threading.Threadobject, notthreading.get_ident(): idents are reused once a thread exits, so the scheduler's fresh teardown thread could get the dead owner's ident and pass the check. preparewaits for the quiet page first, then tags the document and arms the watch (the prompt's sketch arms first and then waits for "no pending mark", which cannot happen while the armed edit watch waits for its edit).--only-shellis not in any changelog (Python and JS release notes); the evidence is the CLI help of the 1.48.0 and 1.49.0 wheels (above).ws_bytesandtransfer_bytesdo not differ betweencpu=1andcpu=4, and should not: a CPU slowdown changes when bytes arrive, not how many.fcp,lcp,interactiveandtbtdiffer as expected (results above).
Interfaces for later PRs
reflex_bench.fixtures.FIXTURES: dict[str, Callable[[Path], None]]—{"playground": stage_playground}; thehmr.*benchmarks takeparams={"app": list(FIXTURES)}, so PR-5 can add generator tiers by adding entries.prime(ctx, fixture)stages and compiles one;app_dir(ctx)/app_env(ctx, app)name the staged app and its environment.reflex_bench.drivers.browser.Browser/Tab/Interactive/Anchor(API above).reflex_bench.drivers.editor.Edit/Target/find_target/text_target.AppProcess.t0andAppProcess.log_lines();owned_processes(token)andkill_owned(token, extra=())inapp_process.
Changes to lower PRs
drivers/app_process.py(#7283):_Outputkeeps each line's read time;AppProcess.t0(property) andAppProcess.log_lines();owned_processes()andkill_owned()(the owner scan and SIGKILL loop made reusable, with PR-3's guards);_ProcessTree.members()usesowned_processes(). Tests added indrivers/test_app_process.py.tests/units/reflex_bench/test_cli.py(#7274):listwithout a suite now lists the 18 browser and hmr instances; the "no benchmarks selected" message is tested with a filter that matches nothing.uv.lock: regenerated with uv 0.12.5 (CI's version). Addingplaywrighttoreflex-benchchanges uv's resolution forks, which also simplifies some unrelated markers (without the dependency,uv lockleaves the file unchanged).
Adversarial self-review
Checked against the prompt's four focus points and CLAUDE.md, then re-read the diff for anything else. Findings and what I did:
- The preview refresh loop lost changes (bug, fixed). The first HEAD
hmr.*run failedhmr.asset.previewinconclude:TimeoutError: the page did not show the restore (naturalWidth of img[alt="Playground logo"]) within 90 s while refreshing it. Two causes:Tab.reload()returned atcommit, so every 250 ms the next refresh aborted a page still loading its uncached logo; and a persisted watch that fired just after a poll gave up lost its mark to the next refresh (the new document re-armed nothing, since the watch had fired, and marks lived in the old document only).reload()now waits for theloadevent, andbench_page.jskeeps the marks of persisted watches insessionStoragetoo; arming an id again clears its mark. Regression test:test_a_reload_keeps_watches_and_marks_but_not_the_alive_tokenfails on the previous script (assert None == {'perf': 216.70000000018626, 'epoch': 1790195826887}) and passes now. Every result above comes from the fixed code. - A change the page never showed gave no clue why (fixed). In the same run
hmr.watcherfailed on its 9th edit: the page never showed a leaf edit, whilehmr.render.leafpassed all 13 of its edits and a stress script (40 edit + restore cycles, 80 changes) never missed one. The error could not say whether granian, the compile or vite dropped it, so_untilnow appendsdescribe_miss(...): when granian saw the change, when the last[timing]line came, whether the page reloaded, the app's last error line (last_error_line), and the page's last uncaught and console errors (Tab.page_errors,Tab.last_error). It did not happen again in ~200 further leaf edits (the stress script, the finalhmr.*run and a 20 + 20 samplehmr.watcher hmr.render.leafrun); the 0.8.23hmr.render.rootfailure above shows what the facts look like. - Teardown from a foreign thread.
Browser.close()/close_tab()compare the thread object (notget_ident(), which a new thread can reuse) and fall back tokill();kill()never touches Playwright, and also kills the Playwright driver, so the abandoned hook getsConnection closed while reading from the driverat once instead of waiting forABANDON_GRACE_S._HotReload._settle()restores the file before checking the thread, then kills the browser from a foreign thread.Browser.start()re-checks_closedafter launching, so a kill during a slow start does not leave a browser behind. Covered by unit tests and by the Ctrl-C run above. - Restore on failure.
concluderestores even whensampleraised (tested),cleanuprestores an edit left behind (tested), and the Ctrl-C run left the staged file identical to the checkout. Residual race, not fixed: if the scheduler's fresh teardown thread restores while the abandoned worker thread is betweenos.replaceandedited = True, the staged copy keeps the edit. The window is microseconds, the checkout is never touched, and the next invocation'ssetup_cacherestages the app. - Marker reuse. Literal edits use
m-<12 hex>from a freshuuid4per try, retries included (tested). CSS and asset values cycle through 160 font sizes and 400 widths, skip the page's original value (tested) and are never the value the page shows when the watch is armed, because every sample restores the original and waits for it before the next edit. - A reload timed as a hot update. The tag is read after the mark and after 0.5 s without DOM mutations, so a reload inside that window is counted and retried. A reload more than 0.5 s after the DOM showed the edit is not attributed to the sample (the next
preparetags the new document); I found no case of it in the runs above, and the forced full reload run shows the detection working. A hot update followed by a reload inside the window counts as a reload: conservative on purpose. - Persisted marks and the tag. With marks surviving reloads, a mark recorded before a full reload is still reported by the new document, but the lost tag still classifies the sample as a reload. The mark's
perfbelongs to the document that recorded it; onlyepochis used for latencies (interactive()reads thehydratedmark, which is never persisted). - Page errors during a preview rebuild. The preview refresh loop can load a half-written build; an uncaught page error there would fail the sample (
raise_errors). Not seen in any preview run; console errors are counted, not fatal. - Clock drift. Latencies use the wall clock on both sides (
time.time_ns()andDate.now()), no anchor involved. The hops map log times through the anchor taken atBrowser.start();CLOCK_MONOTONICandCLOCK_REALTIMEare slewed alike by NTP, so only a clock step would shift them. - Timeouts.
WAIT_S(90 s) is below the hooks' 120 s timeout, so a change that never shows fails with a clear message instead of a scheduler timeout; onereload()can still block up to 120 s, in which case the scheduler's timeout and the kill path take over. - The app's error line is a heuristic.
ERROR_LINEtakes the last line after the edit that starts an error (Error:,…Error:,[ERROR]). A benign error line would show up in the message, labeled as the app's, but it never changes a result; it only annotates a failure that already happened.
Review fixes (0886cbaa9)
These supersede the matching parts above, including deviation 11 and the kill, full-reload and timeout paragraphs.
Browser.kill()works on stock hosts. Chromium clears its environment, so the owner-token scan found nothing on Ubuntu: a timeout leaked Chromium and its driver, and the next benchmark's hook outlivedABANDON_GRACE_S. Nowstart()records the Playwright driver (the harness's child) and its children. Chromium's root leads its own process group with all helpers.kill()calls the newapp_process.kill_processes(): SIGKILL, pluskillpgfor group leaders, with the existing guards against pid/pgid ≤ 1 and the harness's own group. The owner-token path (owned_processes/kill_owned,_driver_of) is removed; #7283's own teardown is unchanged. The 3 kill tests pass on this host.--timeout 0.7onbrowser.dev.ready+hmr.render.leafleaves no processes and no kept workdir.sampletimes only the measurement (safe forbenchmark.pedantic). HMRsampletriggers the edit, waits for the mark, and returns. The page's marks carry the document tag, so full reloads are counted without a round trip.concludedoes the quiet wait, the tag re-check and the restore, and raisesFullReloadErrorfor hot-update-only benchmarks. The in-sample retries are removed; the PR's data showed no reloads in any real sample. Page load: the settle wait andsizes()round trips are removed.transfer_bytesis now summed from CDPNetwork.loadingFinished.encodedDataLength, meaning wire bytes including headers (321.2 kB vs 315.4 kB body-only).- One deadline per hook: every wait in a hook shares the remaining budget, so no hook can outlive its timeout.
- Exact byte counts:
ws_bytesandtransfer_bytesareassume="exact". - Warmup:
browser.*.readyuseswarmup=1, since the first start is much slower. - Clock resolution documented: page times go through the integer-ms
Date.now(), so the anchor is good to about 1 ms.lcpandfcpare both kept (the spec lists both) and coincide on the playground. - Dead code removed:
Tab.pending(),Browser.closed,Interactive.navigation_start,time_origin, and the error-line heuristics.fixture_hash(name)now takes the fixture name.
Checks: 566 passed, 4 skipped; ruff, pyright and pre-commit pass. Real runs (HEAD): browser.dev.ready interactive 2.257 s, hmr.render.leaf 876 ms, hmr.handler 745 ms, full_reloads 0. Ctrl-C mid-edit restores the file and leaves nothing; hash_examples.py --check passes.
Not changed yet (maintainer decision pending): which HMR benchmarks to keep (preview variants, hmr.asset, hmr.reconnect, hmr.watcher).
hmr.css and hmr.asset root causes (404c9ceb1)
Both used to fail every run after a ~94 s timeout.
hmr.css: a real Reflex regression on HEAD; 0.8.23 is fine. Since #7078 (074a818de, released in v0.9.12),reflex/compiler/utils.pyemits<link rel="preload" as="style" href=…/__reflex_global_styles.css?url>before the<link rel="stylesheet">. In dev, the backend recompiles and copies the stylesheet, and Vite sends acss-update. But Vite's client swaps the first<link>whose href matches, which is the preload, so the page keeps the old style until a manual reload. The browser warns "preloaded using link preload but not used". A manual repro (reflex run --env dev+ Playwright) confirms it; on 0.8.23 the change applies in under 0.4 s. The benchmark now detects the dropped update and fails in ~10 s withDroppedUpdateError: vite sent the stylesheet's hot update … but the page did not apply it: font-size … is still '12px', instead of timing out.hmr.asset: expected Vite behavior on both versions. Files inpublic/have no module, so Vite sends neither a hot update nor a reload ("no modules matched"); the user refreshes. The benchmark now refreshes every 250 ms until the new image shows, and reports that aslatency, with the number of refreshes in extra. Measured: HEAD 849 ms, 0.8.23 554 ms.
Tests: 2 new, 3 adjusted; 568 passed; ruff, pyright and pre-commit pass.
Framework fix moved to #7317
The dev stylesheet hot-update regression that hmr.css found is fixed in its own PR against main: #7317 ("emit the global stylesheet preload only in production builds"). That lets it ship without waiting for this stack. Until #7317 merges, hmr.css on HEAD fails fast with DroppedUpdateError, which is the benchmark doing its job.