Skip to content

Commit 0a8b8a8

Browse files
Alek99Alek Petuskey
andauthored
Benchmarking Updates (reflex-dev#3680)
* Benchmark test * Lighthouse posthog --------- Co-authored-by: Alek Petuskey <alekpetuskey@Aleks-MacBook-Pro.local>
1 parent 458cbfa commit 0a8b8a8

9 files changed

Lines changed: 275 additions & 282 deletions

‎.github/workflows/benchmarks.yml‎

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ env:
1818
PYTHONIOENCODING: 'utf8'
1919
TELEMETRY_ENABLED: false
2020
NODE_OPTIONS: '--max_old_space_size=4096'
21-
DATABASE_URL: ${{ secrets.DATABASE_URL }}
2221
PR_TITLE: ${{ github.event.pull_request.title }}
2322

2423
jobs:
@@ -62,17 +61,16 @@ jobs:
6261
run: |
6362
# Check that npm is home
6463
npm -v
65-
poetry run bash scripts/benchmarks/benchmarks.sh ./reflex-web prod
64+
poetry run bash benchmarks/lighthouse.sh ./reflex-web prod
6665
env:
6766
LHCI_GITHUB_APP_TOKEN: $
6867
- name: Run Benchmarks
6968
# Only run if the database creds are available in this context.
70-
if: ${{ env.DATABASE_URL }}
71-
run: poetry run python scripts/benchmarks/lighthouse_score_upload.py "$GITHUB_SHA" ./integration/benchmarks/.lighthouseci
69+
run: poetry run python benchmarks/benchmark_lighthouse.py "$GITHUB_SHA" ./integration/benchmarks/.lighthouseci
7270
env:
7371
GITHUB_SHA: ${{ github.sha }}
7472

75-
simple-apps-benchmarks:
73+
simple-apps-benchmarks: # This app tests the compile times of various compoonents and pages
7674
if: github.event.pull_request.merged == true
7775
env:
7876
OUTPUT_FILE: benchmarks.json
@@ -116,8 +114,6 @@ jobs:
116114
python-version: ${{ matrix.python-version }}
117115
run-poetry-install: true
118116
create-venv-at-path: .venv
119-
- name: Install additional dependencies for DB access
120-
run: poetry run uv pip install psycopg2-binary
121117
- name: Run benchmark tests
122118
env:
123119
APP_HARNESS_HEADLESS: 1
@@ -126,16 +122,14 @@ jobs:
126122
poetry run pytest -v benchmarks/ --benchmark-json=${{ env.OUTPUT_FILE }} -s
127123
- name: Upload benchmark results
128124
# Only run if the database creds are available in this context.
129-
if: ${{ env.DATABASE_URL }}
130125
run:
131-
poetry run python scripts/benchmarks/simple_app_benchmark_upload.py --os "${{ matrix.os }}"
126+
poetry run python benchmarks/benchmark_compile_times.py --os "${{ matrix.os }}"
132127
--python-version "${{ matrix.python-version }}" --commit-sha "${{ github.sha }}"
133-
--benchmark-json "${{ env.OUTPUT_FILE }}"
134-
--db-url "${{ env.DATABASE_URL }}" --branch-name "${{ github.head_ref || github.ref_name }}"
135-
--event-type "${{ github.event_name }}" --actor "${{ github.actor }}" --pr-id "${{ github.event.pull_request.id }}"
128+
--benchmark-json "${{ env.OUTPUT_FILE }}" --branch-name "${{ github.head_ref || github.ref_name }}"
129+
--event-type "${{ github.event_name }}" --pr-id "${{ github.event.pull_request.id }}"
136130

137-
reflex-build-size:
138-
if: github.event.pull_request.merged == true
131+
reflex-dist-size: # This job is used to calculate the size of the Reflex distribution (wheel file)
132+
if: github.event.pull_request.merged == true
139133
timeout-minutes: 30
140134
strategy:
141135
# Prioritize getting more information out of the workflow (even if something fails)
@@ -148,22 +142,19 @@ jobs:
148142
python-version: 3.11.5
149143
run-poetry-install: true
150144
create-venv-at-path: .venv
151-
- name: Install additional dependencies for DB access
152-
run: poetry run uv pip install psycopg2-binary
153145
- name: Build reflex
154146
run: |
155147
poetry build
156148
- name: Upload benchmark results
157149
# Only run if the database creds are available in this context.
158-
if: ${{ env.DATABASE_URL }}
159150
run:
160-
poetry run python scripts/benchmarks/benchmark_reflex_size.py --os ubuntu-latest
151+
poetry run python benchmarks/benchmark_package_size.py --os ubuntu-latest
161152
--python-version 3.11.5 --commit-sha "${{ github.sha }}" --pr-id "${{ github.event.pull_request.id }}"
162-
--db-url "${{ env.DATABASE_URL }}" --branch-name "${{ github.head_ref || github.ref_name }}"
163-
--measurement-type "reflex-build" --path ./dist
153+
--branch-name "${{ github.head_ref || github.ref_name }}"
154+
--path ./dist
164155

165-
reflex-plus-dependency-size:
166-
if: github.event.pull_request.merged == true
156+
reflex-venv-size: # This job calculates the total size of Reflex and its dependencies
157+
if: github.event.pull_request.merged == true
167158
timeout-minutes: 30
168159
strategy:
169160
# Prioritize getting more information out of the workflow (even if something fails)
@@ -197,14 +188,10 @@ jobs:
197188
run: |
198189
poetry run pip install uv
199190
200-
- name: Install additional dependencies for DB access
201-
run: poetry run uv pip install psycopg2-binary
202-
203-
- if: ${{ env.DATABASE_URL }}
204-
name: calculate and upload size
191+
- name: calculate and upload size
205192
run:
206-
poetry run python scripts/benchmarks/benchmark_reflex_size.py --os "${{ matrix.os }}"
193+
poetry run python benchmarks/benchmark_package_size.py --os "${{ matrix.os }}"
207194
--python-version "${{ matrix.python-version }}" --commit-sha "${{ github.sha }}"
208-
--pr-id "${{ github.event.pull_request.id }}" --db-url "${{ env.DATABASE_URL }}"
195+
--pr-id "${{ github.event.pull_request.id }}"
209196
--branch-name "${{ github.head_ref || github.ref_name }}"
210-
--measurement-type "reflex-package" --path ./.venv
197+
--path ./.venv

‎.github/workflows/integration_tests.yml‎

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ env:
3030
PYTHONIOENCODING: 'utf8'
3131
TELEMETRY_ENABLED: false
3232
NODE_OPTIONS: '--max_old_space_size=4096'
33-
DATABASE_URL: ${{ secrets.DATABASE_URL }}
3433
PR_TITLE: ${{ github.event.pull_request.title }}
3534

3635
jobs:
@@ -100,27 +99,25 @@ jobs:
10099
npm -v
101100
poetry run bash scripts/integration.sh ./reflex-examples/counter dev
102101
- name: Measure and upload .web size
103-
if: ${{ env.DATABASE_URL}}
104102
run:
105-
poetry run python scripts/benchmarks/benchmark_reflex_size.py --os "${{ matrix.os }}"
103+
poetry run python benchmarks/benchmark_web_size.py --os "${{ matrix.os }}"
106104
--python-version "${{ matrix.python-version }}" --commit-sha "${{ github.sha }}"
107-
--pr-id "${{ github.event.pull_request.id }}" --db-url "${{ env.DATABASE_URL }}"
105+
--pr-id "${{ github.event.pull_request.id }}"
108106
--branch-name "${{ github.head_ref || github.ref_name }}"
109-
--measurement-type "counter-app-dot-web" --path ./reflex-examples/counter/.web
107+
--path ./reflex-examples/counter/.web
108+
--app-name "counter"
110109
- name: Install hyperfine
111110
run: cargo install hyperfine
112111
- name: Benchmark imports
113112
working-directory: ./reflex-examples/counter
114113
run: hyperfine --warmup 3 "export POETRY_VIRTUALENVS_PATH=../../.venv; poetry run python counter/counter.py" --show-output --export-json "${{ env.OUTPUT_FILE }}" --shell bash
115114
- name: Upload Benchmarks
116-
if : ${{ env.DATABASE_URL }}
117115
run:
118-
poetry run python scripts/benchmarks/benchmark_imports.py --os "${{ matrix.os }}"
116+
poetry run python benchmarks/benchmark_imports.py --os "${{ matrix.os }}"
119117
--python-version "${{ matrix.python-version }}" --commit-sha "${{ github.sha }}"
120118
--benchmark-json "./reflex-examples/counter/${{ env.OUTPUT_FILE }}"
121-
--db-url "${{ env.DATABASE_URL }}" --branch-name "${{ github.head_ref || github.ref_name }}"
122-
--event-type "${{ github.event_name }}" --actor "${{ github.actor }}" --pr-id "${{ github.event.pull_request.id }}"
123-
119+
--branch-name "${{ github.head_ref || github.ref_name }}" --pr-id "${{ github.event.pull_request.id }}"
120+
--app-name "counter"
124121

125122

126123

@@ -164,10 +161,8 @@ jobs:
164161
npm -v
165162
poetry run bash scripts/integration.sh ./reflex-web prod
166163
- name: Measure and upload .web size
167-
if: ${{ env.DATABASE_URL}}
168164
run:
169-
poetry run python scripts/benchmarks/benchmark_reflex_size.py --os "${{ matrix.os }}"
165+
poetry run python benchmarks/benchmark_web_size.py --os "${{ matrix.os }}"
170166
--python-version "${{ matrix.python-version }}" --commit-sha "${{ github.sha }}"
171-
--pr-id "${{ github.event.pull_request.id }}"
172-
--db-url "${{ env.DATABASE_URL }}" --branch-name "${{ github.head_ref || github.ref_name }}"
173-
--measurement-type "reflex-web-dot-web" --path ./reflex-web/.web
167+
--pr-id "${{ github.event.pull_request.id }}" --branch-name "${{ github.head_ref || github.ref_name }}"
168+
--app-name "reflex-web" --path ./reflex-web/.web

scripts/benchmarks/simple_app_benchmark_upload.py renamed to benchmarks/benchmark_compile_times.py

Lines changed: 16 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
"""Runs the benchmarks and inserts the results into the database."""
1+
"""Extracts the compile times from the JSON files in the specified directory and inserts them into the database."""
22

33
from __future__ import annotations
44

55
import argparse
66
import json
77
import os
8-
from datetime import datetime
98

10-
import psycopg2
9+
from utils import send_data_to_posthog
1110

1211

1312
def extract_stats_from_json(json_file: str) -> list[dict]:
@@ -51,60 +50,40 @@ def extract_stats_from_json(json_file: str) -> list[dict]:
5150

5251

5352
def insert_benchmarking_data(
54-
db_connection_url: str,
5553
os_type_version: str,
5654
python_version: str,
5755
performance_data: list[dict],
5856
commit_sha: str,
5957
pr_title: str,
6058
branch_name: str,
6159
event_type: str,
62-
actor: str,
6360
pr_id: str,
6461
):
6562
"""Insert the benchmarking data into the database.
6663
6764
Args:
68-
db_connection_url: The URL to connect to the database.
6965
os_type_version: The OS type and version to insert.
7066
python_version: The Python version to insert.
7167
performance_data: The performance data of reflex web to insert.
7268
commit_sha: The commit SHA to insert.
7369
pr_title: The PR title to insert.
7470
branch_name: The name of the branch.
75-
event_type: Type of github event(push, pull request, etc)
76-
actor: Username of the user that triggered the run.
71+
event_type: Type of github event(push, pull request, etc).
7772
pr_id: Id of the PR.
7873
"""
79-
# Serialize the JSON data
80-
simple_app_performance_json = json.dumps(performance_data)
81-
82-
# Get the current timestamp
83-
current_timestamp = datetime.now()
84-
85-
# Connect to the database and insert the data
86-
with psycopg2.connect(db_connection_url) as conn, conn.cursor() as cursor:
87-
insert_query = """
88-
INSERT INTO simple_app_benchmarks (os, python_version, commit_sha, time, pr_title, branch_name, event_type, actor, performance, pr_id)
89-
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s);
90-
"""
91-
cursor.execute(
92-
insert_query,
93-
(
94-
os_type_version,
95-
python_version,
96-
commit_sha,
97-
current_timestamp,
98-
pr_title,
99-
branch_name,
100-
event_type,
101-
actor,
102-
simple_app_performance_json,
103-
pr_id,
104-
),
105-
)
106-
# Commit the transaction
107-
conn.commit()
74+
# Prepare the event data
75+
properties = {
76+
"os": os_type_version,
77+
"python_version": python_version,
78+
"distinct_id": commit_sha,
79+
"pr_title": pr_title,
80+
"branch_name": branch_name,
81+
"event_type": event_type,
82+
"performance": performance_data,
83+
"pr_id": pr_id,
84+
}
85+
86+
send_data_to_posthog("simple_app_benchmark", properties)
10887

10988

11089
def main():
@@ -124,11 +103,6 @@ def main():
124103
"--benchmark-json",
125104
help="The JSON file containing the benchmark results.",
126105
)
127-
parser.add_argument(
128-
"--db-url",
129-
help="The URL to connect to the database.",
130-
required=True,
131-
)
132106
parser.add_argument(
133107
"--pr-title",
134108
help="The PR title to insert into the database.",
@@ -143,11 +117,6 @@ def main():
143117
help="The github event type",
144118
required=True,
145119
)
146-
parser.add_argument(
147-
"--actor",
148-
help="Username of the user that triggered the run.",
149-
required=True,
150-
)
151120
parser.add_argument(
152121
"--pr-id",
153122
help="ID of the PR.",
@@ -162,15 +131,13 @@ def main():
162131
cleaned_benchmark_results = extract_stats_from_json(args.benchmark_json)
163132
# Insert the data into the database
164133
insert_benchmarking_data(
165-
db_connection_url=args.db_url,
166134
os_type_version=args.os,
167135
python_version=args.python_version,
168136
performance_data=cleaned_benchmark_results,
169137
commit_sha=args.commit_sha,
170138
pr_title=pr_title,
171139
branch_name=args.branch_name,
172140
event_type=args.event_type,
173-
actor=args.actor,
174141
pr_id=args.pr_id,
175142
)
176143

0 commit comments

Comments
 (0)