Performance benchmarking
The Reflex performance benchmark system measures user-visible speed, resource use, and runtime behavior across the Python runtime, generated browser app, event path, memory use, lifecycle commands, and shipped assets. It turns each run into a recorded result that can be compared with a baseline or checked against a fixed budget.
Use the child pages for benchmark suite execution, benchmark collection, benchmark comparison, and benchmark reporting. The related benchmark harness and reporting page gives a combined view of the framework's operating parts, while release engineering explains how performance checks fit release controls.
Benchmark framework
Measurement goals
The framework answers two related questions: did a change alter a measured behavior, and does the result stay within the limit that the product accepts? It uses the real Reflex command line and external process boundaries for broad checks, while focused pytest benchmarks isolate lower-level runtime work.
The repository has two complementary benchmark layers:
| Layer | Purpose | Main signal |
|---|---|---|
| Runtime benchmarks | Isolate Python and state or event processing work | CodSpeed timing comparisons from tests/benchmarks |
| Macro benchmarks | Exercise a complete Reflex app through commands, HTTP, sockets, or a browser | Stored samples, comparisons, budgets, and reports from reflex-bench |
Benchmark CI uses the dedicated bench dependency group from home/…/pyproject.toml. The group installs reflex-bench and the plotting package needed by the benchmark playground without the full development group. This keeps the measurement environment separate from unrelated development dependencies and avoids the arm64 libsass source-build path.
The benchmark harness and reporting page gives the detailed view of command orchestration, subjects, collectors, baselines, and reports.
References: packages/…/README.md• L3-10 tests/…/README.md• L1-18 .github/…/performance.yml• L48-73 pyproject.toml• L88-147
Benchmark coverage
The benchmark suites model the main paths through which a Reflex change can affect users. Each suite measures a behavior with named metrics and can use a smaller selection for a quick check or a wider selection for a daily run.
| Area | What the measurements represent |
|---|---|
| Runtime and lifecycle | Time and resource cost of app initialization, compilation, export, startup, readiness, and hot reload |
| Browser behavior | Hydration, page load, state-to-DOM updates, navigation, paint work, browser heap, and client bundle size |
| Memory behavior | Compile and server peaks, idle use, per-session growth, leak trends, and operation under a memory limit |
| Event behavior | Event capacity, response latency, ordering, queueing, handler work, shared-state contention, and cleanup |
| Wire behavior | Bytes and frames sent during hydration, events, navigation, and state deltas |
| Shipped size | Raw and compressed client assets plus the wider exported web output |
These areas connect product behavior to a common result model. For example, a state change can appear as event latency, a browser update, and a larger websocket delta, so the framework keeps those signals separate instead of hiding one cost inside another.
References: packages/…/lifecycle.py• L340-397 packages/…/browser.py• L165-209 packages/…/memory.py• L913-1086 packages/…/events.py• L920-1036 packages/…/wire.py• L753-870 packages/…/size.py• L303-330
Benchmark lifecycle
Suite selection
The suite registry is the map from a benchmark definition to the checks run in a given context. A benchmark has an id, a set of metrics, optional parameters, and membership in named selections such as smoke, pr, daily, all, or selftest.
The usual selection model is:
smokechecks a small set of representative points.prgives pull requests a useful signal within a short run.dailycovers wider workloads and longer-running behavior.allselects every non-self-test benchmark.selftestchecks that the harness itself can measure, fail, time out, and compare work correctly.
The registry expands parameter choices into benchmark instances. This lets one behavior be measured at several loads or app sizes without treating each choice as a separate framework.
References: packages/…/registry.py• L55-59 packages/…/registry.py• L210-249 packages/…/registry.py• L397-430 packages/…/registry.py• L666-713
Run flow
The run flow resolves the Reflex subject, selects benchmark instances, collects samples, writes the result, and then applies any requested comparison or budget check. CI uses the same command path as local runs, with different output and failure settings.
The following diagram shows how a benchmark request becomes a performance decision.
flowchart LR
A[Select suite or id] --> B[Resolve Reflex subject]
B --> C[Prepare app and measurement context]
C --> D[Warm up and collect samples]
D --> E[Summarize raw result]
E --> F{Compare baseline?}
F -->|yes| G[Statistical verdicts]
F -->|no| H[Standalone report]
G --> I{Check budgets?}
H --> I
I --> J[Exit status and saved artifacts]
The command supports direct runs, alternating A/B runs, result inspection, comparison, export, machine checks, and subject-cache management. This makes the command line the shared contract for developers and automation.
References: packages/…/cli.py• L161-165 packages/…/cli.py• L715-904 packages/…/cli.py• L907-1109 packages/…/README.md• L25-76
Measurement boundaries
The macro harness measures Reflex as a user or process would use it. It starts the subject with its own interpreter and drives it through subprocesses, HTTP, sockets, or a headless browser rather than importing the subject into the harness. This keeps the measured boundary close to the real command, server, network, and browser path.
Each result records the subject, machine profile, fixture identity, policy, raw samples, and extra sample data. The record also keeps the effective settings that shaped the run, so a later reader can tell whether two results used the same workload and measurement conditions.
References: packages/…/README.md• L7-10 packages/…/README.md• L78-118 packages/…/schema.py• L65-140 packages/…/schema.py• L203-257
Result interpretation
Sample statistics
The framework stores every raw sample and derives summaries from those samples. Warm-up samples are kept for traceability but are not used for timed results. Metrics declare whether lower or higher is better and whether a value is expected to be exact or subject to normal run-to-run variation.
For variable measurements, comparisons use the sample distributions rather than one point. The framework reports a median and confidence interval, applies a significance test with Holm correction across the comparison, and can mark a result as inconclusive when the samples do not support a clear verdict. Outliers remain in the data instead of being removed silently.
References: packages/…/schema.py• L9-11 packages/…/registry.py• L65-81 packages/…/compare.py• L1-11 packages/…/compare.py• L222-274 packages/…/stats.py• L1-8
Baseline comparison
Comparison pairs a head result with a base result only when the benchmark instance and its measurement series describe the same work. The pairing includes the subject or arm, machine profile, fixture identity, benchmark definition version, parameters, and dimensions that affect measurement.
When the series do not match, the framework reports why the result is not comparable instead of producing a misleading change. A benchmark that fails or times out in the head when it did not fail in the base is treated as a regression. An A/B run uses the same comparison model while alternating the two subjects on one machine to reduce machine drift.
References: packages/…/compare.py• L105-203 packages/…/compare.py• L275-301 packages/…/store.py• L1-11 packages/…/registry.py• L210-232
Budget evaluation
Budgets are fixed maximum values for named benchmark metrics. The current budget file gates exported playground size, including initial compressed assets, total compressed assets, chunk count, and the exported node_modules size; other recorded metrics can remain visible without being gated.
Budget checks use the largest timed sample for each budgeted metric. A value over its limit returns a regression status. A missing benchmark, failed benchmark, or missing metric returns an unchecked error because the system cannot prove that the budget passed.
References: packages/…/budgets.json• L1-12 packages/…/budgets.py• L1-16 packages/…/budgets.py• L121-167 packages/…/budgets.py• L241-294
Continuous integration
Performance workflow
The performance workflow runs three groups of checks. It runs CodSpeed runtime benchmarks, event-loop and wire-size smoke checks, browser performance and bundle-budget smoke checks, and a separate Lighthouse check. Each group uploads its result files so a failed or changed signal can be inspected after the job ends.
The workflow fixes settings that can add unrelated noise, such as Python hash order and telemetry. A final gate combines the job results into the status required by branch rules, so a skipped or failed performance group cannot silently remove the overall signal.
References: .github/…/performance.yml• L14-29 .github/…/performance.yml• L48-74 .github/…/performance.yml• L76-110 .github/…/performance.yml• L112-163
Performance artifacts
The pytest performance checks write structured reports and traces for event-loop, wire-size, browser, and related scenarios. These checks complement the macro result documents: they provide focused diagnostics for runtime behavior while reflex-bench provides comparable samples and budget decisions across subjects.
The artifact path is part of the CI contract. A change to a report name or output location can make a successful measurement invisible to reviewers even when the test still runs.
References: tests/…/test_event_loop.py• L593-709 tests/…/test_wire_size.py• L53-94 tests/…/test_browser.py• L73-167 .github/…/performance.yml• L60-73
Change checklist
When these files or sections are changed, remember to consider these:
- When a metric, unit, direction, or benchmark id changes, update its budget entry and any consumers that pair or render the result by name.
- When a fixture or workload changes, preserve its content identity so comparisons reject mismatched series instead of treating new work as a regression.
- When a performance report path or file name changes, update the matching CI artifact path.
- When a suite's parameter grid changes, check that
smokeremains small enough for pull requests and thatdailystill covers the intended load. - When a result schema field changes, keep raw samples and derived summaries aligned so old result files remain useful.
- When the benchmark dependency group changes, check that CI still installs the focused harness environment and that platform-specific source builds do not return to the benchmark jobs.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A benchmark result uses a different machine, fixture, or benchmark definition series | The comparison is not valid or is reported as not comparable | The result records series identity and comparison checks the full series key |
| A budgeted benchmark is missing, failed, or lacks the named metric | The budget cannot be proven and the check returns an error | The budget command marks the row unchecked instead of passing it |
| A head benchmark fails or times out when the base passed | The behavior is treated as a regression | Comparison records failed-in-head entries separately from metric changes |
| A performance report moves without a workflow update | CI may run the check but upload no useful artifact | Keep report output paths aligned with the workflow artifact paths |
| A load generator or host adds measurement noise | A result can become unstable or inconclusive | Use fixed CI settings, machine checks, warmups, repeated samples, and confidence intervals |
| The benchmark job installs the full development environment or a platform-specific source build returns | CI spends time on unrelated packages or fails before measurement starts | Use the focused bench dependency group for the harness |
Key files
| File | Why to read it |
|---|---|
| packages/…/README.md | Gives the user-facing model of suites, subjects, benchmark areas, and result behavior. |
| pyproject.toml | Defines the focused dependency group used to install the benchmark harness and its playground dependency in CI. |
| packages/…/cli.py | Shows the command-level flow from selection through saving, comparison, and exit status. |
| packages/…/registry.py | Defines benchmark identity, metrics, parameterized instances, and suite selection. |
| packages/…/schema.py | Defines the stored result contract and the link between raw samples and summaries. |
| packages/…/compare.py | Defines pairing, statistical verdicts, failed-head handling, and incomparability. |
| packages/…/budgets.py | Defines fixed metric limits and the budget-check result states. |
| packages/…/budgets.json | Shows the current shipped-size budgets. |
| .github/…/performance.yml | Shows how runtime, smoke, browser, bundle, and Lighthouse checks run in CI. |
| tests/…/README.md | Explains the focused runtime benchmark layer and its measurement boundaries. |
| tests/…/test_event_loop.py | Shows the event-loop behavior and diagnostic artifact signal. |
| tests/…/test_browser.py | Shows the browser, heap, and client-bundle performance signal. |