Introducing a new way to review your PRs.

Read the announcement

reflex-dev / reflex

🕸️ Web apps in pure Python 🐍

View on GitHub

30 documents · Updated Nov 23, 2026

docs / benchmark-harness

Benchmark harness and reporting

The benchmark harness measures Reflex behavior through a single command-line workflow. It selects benchmark instances and subjects, drives Reflex as an external process or browser app, records raw samples with machine context, and turns the result into budgets, comparisons, and review reports. See the parent page, Performance benchmarking, for the wider performance process.

System scope

The harness keeps the code under test outside its own Python process. This boundary makes a result describe the Reflex subject as a user would run it, rather than a direct in-process call. The same CLI path runs locally and in CI. CI changes output and exit policy, but it does not use a separate measurement system.

The main flow moves from a selection to a stored result and then to one or more evaluations:

flowchart LR
    A[CLI command] --> B[Select suites and subjects]
    B --> C[Plan benchmark instances]
    C --> D[Drive Reflex or browser]
    D --> E[Collect raw samples]
    E --> F[Validate and store result]
    F --> G[Check budgets]
    F --> H[Compare with baseline]
    H --> I[Render terminal, Markdown, or BMF report]

CLI orchestration

Command surface

The packages/…/cli.py command group is the public control point for listing, running, comparing, exporting, and checking benchmark data. list shows the planned work before execution. run measures one subject. ab measures two subjects in an interleaved run. show, compare, and export consume stored result documents without measuring again. doctor reports machine conditions that can affect the signal.

The CLI also owns the contract with automation. It records the effective policy in each result and uses distinct exit codes for harness errors, regressions, inconclusive comparisons, and interruption. A failed or timed-out benchmark is captured in the result so other selected instances can continue.

References: packages/…/cli.py• L1-10 packages/…/cli.py• L161-165 packages/…/README.md• L25-76

Run lifecycle

The scheduler expands each selected benchmark into parameter instances and runs each instance through a fixed lifecycle. It prepares shared cached state, opens the instance, performs warmups and timed samples, then always performs teardown. This gives a benchmark a place to create a service, reset state, take a sample, and remove the service without coupling those actions to the CLI.

The run policy controls warmups, timeouts, sample count, confidence, practical change threshold, and failure behavior. Automatic runs use the first timed sample to select a bounded count. Smoke runs favor a quick health check over statistical strength. The result stores these choices so a later reader can tell how the measurement was made.

References: packages/…/scheduler.py• L1-16 packages/…/scheduler.py• L97-179 packages/…/registry.py• L17-20

Benchmark and subject selection

Suite registration

Benchmark suites are named selections over registered benchmark definitions. Suite modules under packages/reflex-bench/src/reflex_bench/suites/ are discovered as a group. A definition supplies an id, measurement kind, metrics, and a parameter grid. A suite can narrow that grid for a quick smoke or pull-request run while the full set remains available for daily or all runs.

This separation lets the same workload serve different review needs. The benchmark definition describes what to measure. The suite describes when and at what size to measure it. Filters then select ids within the chosen suite.

References: packages/…/registry.py• L1-20 packages/…/registry.py• L55-59 packages/…/cli.py• L227-273

Subject registration

A subject is the Reflex installation under test. The harness accepts the current workspace, a package version, a Git reference, or another local checkout. Non-workspace subjects receive isolated environments, which keeps the harness and the subject's dependencies separate. The subject record carries the code identity and interpreter details needed to explain and repeat a result.

The subject's interpreter is placed first in the subprocess environment. This makes commands started by Reflex resolve to the subject's tools. The harness reads package metadata through the subject interpreter and does not import the Reflex package under test.

References: packages/…/subjects.py• L1-26 packages/…/subjects.py• L119-171 packages/…/context.py• L1-6 packages/…/context.py• L122-173

Drivers and metric collection

Application driver

The application driver starts Reflex through the subject interpreter and treats readiness as an externally visible event. It checks both the announced endpoints and their network behavior. It then provides one-shot command runs or a long-lived app process that can be stopped as a whole process tree.

This driver supports lifecycle, event, memory, and reload workloads. It also gives measurements a common boundary for command wall time, CPU time, process-tree memory, and readiness. The process mode and Reflex version determine the expected endpoint shape, so older and newer subjects can be measured through the same benchmark contract.

References: packages/…/app_process.py• L1-17 packages/…/app_process.py• L220-252 packages/…/context.py• L33-49

Browser driver

The browser driver measures behavior that exists only after a page loads. It runs a headless Chromium session with a fresh page context and observes page marks, network transfer, WebSocket traffic, console errors, and hydration. Browser readiness is separate from process and HTTP readiness, which lets reports show where startup time is spent.

Browser marks use the page clock and an anchor to the harness clock. This connects page events to app start without treating a browser log line as the measurement itself. The browser benchmark suite uses these signals for development, preview, and production startup and page-load views.

References: packages/…/browser.py• L1-25 packages/…/browser.py• L126-173 packages/…/browser.py• L1-7 packages/…/browser.py• L29-37

Metric collectors

Collectors turn process and application observations into declared benchmark metrics. A benchmark declares each metric's unit and whether a higher or lower value is better. Raw values use stable base units. The report layer scales them for display.

The harness prefers whole-process-tree counters when the host supports a cgroup scope. It falls back to sampled proportional set size for memory when that scope is not available. These methods are recorded as dimensions and are not mixed in one comparison series. Phase collection adds a broad split between Python, frontend tools, and package installation when a command needs an explanation beyond one duration.

References: packages/…/registry.py• L65-108 packages/…/app_process.py• L243-260 packages/…/cgroup.py• L1-14 packages/…/pss.py• L1-8 packages/…/phases.py• L1-15

Result and baseline management

Result documents

Each invocation produces one versioned JSON result document. It keeps the subject and machine identity, effective policy, benchmark status, raw samples, per-sample extra data, summaries, warnings, and any comparison verdicts. Summaries and comparisons are derived from the raw samples, so the document preserves the evidence needed to inspect or recompute the result.

Validation occurs when result documents are loaded and written. This protects later commands from silently reading a partial or incompatible shape. A result can therefore move from the run command to budget checks, comparisons, and report exports without changing its meaning.

References: packages/…/schema.py• L1-10 packages/…/schema.py• L22-39 packages/…/README.md• L896-905

Baseline storage

Autosaved results and named baselines are stored under a machine profile. The profile keeps results from different operating systems, CPUs, and Python versions from being compared as if they came from the same measurement setting. A baseline can be addressed by file, name, or autosave number.

Benchmark caches are separate from result files. They preserve reusable setup work for a subject and parameter set, while each benchmark still controls what is safe to reuse. This supports warm and cold workload definitions without treating setup artifacts as measured output.

References: packages/…/store.py• L1-11 packages/…/store.py• L32-46 packages/…/store.py• L158-187 packages/…/context.py• L198-220

Evaluation and reporting

Budget evaluation

Budgets are fixed upper limits for selected benchmark metrics. The budget file names an instance and its metric, while the result supplies the measured value. The check reports the value, limit, delta, and verdict. A missing benchmark, failed benchmark, or missing metric is an unchecked budget rather than a pass.

Budgets gate known product limits. Metrics without a budget remain useful for trend tracking but do not fail the budget command. The default budget file is packages/…/budgets.json, and a limit change is visible when it travels with the same review as the measurement change.

References: packages/…/budgets.py• L1-16 packages/…/budgets.py• L121-167 packages/…/budgets.py• L236-255

Baseline comparison

Comparison pairs benchmark entries by id, visible parameters, and measurement dimensions. It also requires the same machine profile, fixture content, and benchmark source version unless the user forces a comparison. This prevents a change in the workload or measurement method from looking like a product regression.

For comparable samples, the harness reports effect size, confidence interval, significance, and a verdict. It applies a practical threshold and corrects significance across the metrics in the comparison. A result is inconclusive when the evidence cannot support a change. Failures in the head that do not exist in the base are treated as regressions even when metric samples are unavailable.

References: packages/…/compare.py• L1-11 packages/…/compare.py• L105-139 packages/…/compare.py• L140-213 packages/…/README.md• L828-852

Report generation

Reports present the same result for different consumers. The terminal view supports live local work and plain CI logs. Markdown puts regressions, improvements, and inconclusive results before unchanged rows so a pull request review starts with the useful signal. Bencher Metric Format exports medians and confidence bounds for an external metric service.

The head result stores comparison annotations. Later show and export commands can therefore render the same verdicts without rerunning the benchmark or repeating the comparison.

References: packages/…/table.py• L1-7 packages/…/markdown.py• L1-6 packages/…/markdown.py• L73-162 packages/…/bmf.py• L1-5 packages/…/bmf.py• L14-40

Change checklist

When these files or sections are changed, remember to consider these:

  • A new metric or changed unit must stay aligned across the benchmark declaration, result schema, comparison direction, budget entry, and report formatting.
  • A new suite or parameter point must keep CLI selection, estimated duration, and CI workflow intent aligned.
  • A changed subject identity or machine profile must preserve cache isolation and must not pair results with an incompatible baseline.
  • A changed readiness signal must keep the application driver, browser driver, and browser benchmark timing tiers consistent.
  • A changed collector method must remain visible in series dimensions so cgroup and sampled memory values cannot compare as one series.
  • A changed result field must remain readable by validation, baseline loading, comparison, and all report exporters.

Important failure modes

TriggerConsequenceGuard
The subject environment is not isolated or is not first on PATHA benchmark measures the harness's Reflex or tools instead of the selected subjectSubject environments and subject_env put the subject interpreter first and record the subject identity
The app prints a ready line but its port is not accepting connectionsStartup time is reported before the service can serve trafficThe application driver requires both expected ready lines and TCP checks
A cgroup scope is unavailablePeak memory falls back to sampled PSS and can miss short spikesRecord the method in dimensions and never compare it with cgroup peaks
A baseline has a different profile, fixture hash, or benchmark versionThe comparison has no valid paired seriesComparison blocks mismatched series unless --force is used
A budgeted benchmark is absent, failed, or lacks its metricThe budget cannot be checked and the command returns an error statusTreat unchecked budgets as distinct from an in-budget value
A hook times out or raises during an instanceThat instance is marked failed or timed out while later instances can still runApply hook deadlines and always attempt conclude and cleanup

Key files

FileWhy to read it
packages/…/README.mdUser-level view of commands, subjects, benchmark kinds, comparisons, budgets, and result storage
packages/…/cli.pyCLI commands, policy handling, persistence, and exit behavior
packages/…/registry.pyBenchmark definitions, metrics, parameters, and suite discovery
packages/…/scheduler.pyInstance planning, lifecycle order, sampling policy, and failure capture
packages/…/subjects.pySubject specs and isolated environments for the code under test
packages/…/app_process.pyExternal Reflex process startup, readiness, and process-tree measurement boundary
packages/…/browser.pyBrowser timing, page marks, network observations, and browser cleanup
packages/…/cgroup.pyWhole-process-tree CPU and memory collection when cgroup scopes are available
packages/…/pss.pySampled memory fallback and its measurement limits
packages/…/schema.pyResult document contract and validation boundary
packages/…/store.pyResult, baseline, and cache locations plus series identity helpers
packages/…/compare.pyPairing rules, statistical comparison, and verdict annotation
packages/…/budgets.pyBudget file validation and budget exit behavior
packages/…/markdown.pyPull request report structure and comparison presentation
packages/…/bmf.pyExport mapping for external metric reporting