Skip to content

Commit a06b570

Browse files
Benchmark with app harness (reflex-dev#2774)
1 parent 2a8d9d1 commit a06b570

12 files changed

Lines changed: 1237 additions & 249 deletions

‎.github/workflows/benchmarks.yml‎

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ env:
2121
PYTHONIOENCODING: 'utf8'
2222
TELEMETRY_ENABLED: false
2323
NODE_OPTIONS: '--max_old_space_size=4096'
24+
DATABASE_URL: ${{ secrets.DATABASE_URL }}
2425

2526
jobs:
2627
reflex-web:
27-
env:
28-
DATABASE_URL: ${{ secrets.DATABASE_URL }}
2928
strategy:
3029
fail-fast: false
3130
matrix:
@@ -70,8 +69,58 @@ jobs:
7069
- name: Run Benchmarks
7170
# Only run if the database creds are available in this context.
7271
if: ${{ env.DATABASE_URL }}
73-
working-directory: ./integration/benchmarks
74-
run: poetry run python benchmarks.py "$GITHUB_SHA" .lighthouseci
72+
run: poetry run python scripts/lighthouse_score_upload.py "$GITHUB_SHA" ./integration/benchmarks/.lighthouseci
7573
env:
7674
GITHUB_SHA: ${{ github.sha }}
7775
PR_TITLE: ${{ github.event.pull_request.title }}
76+
77+
simple-apps-benchmarks:
78+
env:
79+
OUTPUT_FILE: benchmarks.json
80+
timeout-minutes: 50
81+
strategy:
82+
# Prioritize getting more information out of the workflow (even if something fails)
83+
fail-fast: false
84+
matrix:
85+
# Show OS combos first in GUI
86+
os: [ubuntu-latest, windows-latest, macos-latest]
87+
python-version: ['3.8.18', '3.9.18', '3.10.13', '3.11.5', '3.12.0']
88+
exclude:
89+
- os: windows-latest
90+
python-version: '3.10.13'
91+
- os: windows-latest
92+
python-version: '3.9.18'
93+
- os: windows-latest
94+
python-version: '3.8.18'
95+
include:
96+
- os: windows-latest
97+
python-version: '3.10.11'
98+
- os: windows-latest
99+
python-version: '3.9.13'
100+
- os: windows-latest
101+
python-version: '3.8.10'
102+
103+
runs-on: ${{ matrix.os }}
104+
steps:
105+
- uses: actions/checkout@v4
106+
- uses: ./.github/actions/setup_build_env
107+
with:
108+
python-version: ${{ matrix.python-version }}
109+
run-poetry-install: true
110+
create-venv-at-path: .venv
111+
- name: Install additional dependencies for DB access
112+
run: poetry run pip install psycopg2-binary
113+
- name: Run benchmark tests
114+
env:
115+
APP_HARNESS_HEADLESS: 1
116+
PYTHONUNBUFFERED: 1
117+
run: |
118+
poetry run pytest -v benchmarks/ --benchmark-json=${{ env.OUTPUT_FILE }} -s
119+
- name: Upload benchmark results
120+
# Only run if the database creds are available in this context.
121+
if: ${{ env.DATABASE_URL }}
122+
run: poetry run python scripts/simple_app_benchmark_upload.py --os "${{ matrix.os }}"
123+
--python-version "${{ matrix.python-version }}" --commit-sha "${{ github.sha }}"
124+
--benchmark-json "${{ env.OUTPUT_FILE }}" --pr-title "${{ github.event.pull_request.title }}"
125+
--db-url "${{ env.DATABASE_URL }}" --branch-name "${{ github.head_ref || github.ref_name }}"
126+
--event-type "${{ github.event_name }}" --actor "${{ github.actor }}"

‎.pre-commit-config.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ repos:
1010
hooks:
1111
- id: ruff
1212
args: [--fix, --exit-non-zero-on-fix]
13+
exclude: '^integration/benchmarks/'
1314

1415
- repo: https://github.com/RobertCraigie/pyright-python
1516
rev: v1.1.313

‎benchmarks/__init__.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"""Reflex benchmarks."""
2+
3+
WINDOWS_SKIP_REASON = "Takes too much time as a result of npm"

‎benchmarks/conftest.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""Shared conftest for all benchmark tests."""
2+
3+
import pytest
4+
5+
from reflex.testing import AppHarness, AppHarnessProd
6+
7+
8+
@pytest.fixture(
9+
scope="session", params=[AppHarness, AppHarnessProd], ids=["dev", "prod"]
10+
)
11+
def app_harness_env(request):
12+
"""Parametrize the AppHarness class to use for the test, either dev or prod.
13+
14+
Args:
15+
request: The pytest fixture request object.
16+
17+
Returns:
18+
The AppHarness class to use for the test.
19+
"""
20+
return request.param

0 commit comments

Comments
 (0)