at least have something

This commit is contained in:
Khaleel Al-Adhami 2025-01-28 13:11:27 -08:00
parent fed9240d13
commit 8c7efa05e1
2 changed files with 22 additions and 114 deletions

1
.gitignore vendored
View File

@ -15,3 +15,4 @@ requirements.txt
.pyi_generator_last_run .pyi_generator_last_run
.pyi_generator_diff .pyi_generator_diff
reflex.db reflex.db
.codspeed

View File

@ -8,9 +8,7 @@ from typing import Generator
import pytest import pytest
from benchmarks import WINDOWS_SKIP_REASON
from reflex import constants from reflex import constants
from reflex.compiler import utils
from reflex.testing import AppHarness, chdir from reflex.testing import AppHarness, chdir
from reflex.utils import build from reflex.utils import build
from reflex.utils.prerequisites import get_web_dir from reflex.utils.prerequisites import get_web_dir
@ -115,34 +113,24 @@ def render_component(num: int):
] * num ] * num
def AppWithTenComponentsOnePage(): # This is a fake component, technically, it's not needed for runtime,
"""A reflex app with roughly 10 components on one page.""" # but it's used to make the type checker happy.
components = 1
def AppWithComponents():
"""Generate an app with a number of components.
Args:
components: The number of components to generate.
Returns:
The generated app.
"""
import reflex as rx import reflex as rx
def index() -> rx.Component: def index() -> rx.Component:
return rx.center(rx.vstack(*render_component(1))) return rx.center(rx.vstack(*render_component(components)))
app = rx.App(_state=rx.State)
app.add_page(index)
def AppWithHundredComponentOnePage():
"""A reflex app with roughly 100 components on one page."""
import reflex as rx
def index() -> rx.Component:
return rx.center(rx.vstack(*render_component(100)))
app = rx.App(_state=rx.State)
app.add_page(index)
def AppWithThousandComponentsOnePage():
"""A reflex app with roughly 1000 components on one page."""
import reflex as rx
def index() -> rx.Component:
return rx.center(rx.vstack(*render_component(1000)))
app = rx.App(_state=rx.State) app = rx.App(_state=rx.State)
app.add_page(index) app.add_page(index)
@ -165,8 +153,9 @@ def app_with_10_components(
yield AppHarness.create( yield AppHarness.create(
root=root, root=root,
app_source=functools.partial( app_source=functools.partial(
AppWithTenComponentsOnePage, AppWithComponents,
render_component=render_component, # type: ignore render_component=render_component, # type: ignore
components=10, # pyright: ignore [reportGeneralTypeIssues]
), ),
) # type: ignore ) # type: ignore
@ -188,8 +177,9 @@ def app_with_100_components(
yield AppHarness.create( yield AppHarness.create(
root=root, root=root,
app_source=functools.partial( app_source=functools.partial(
AppWithHundredComponentOnePage, AppWithComponents,
render_component=render_component, # type: ignore render_component=render_component, # type: ignore
components=100, # pyright: ignore [reportGeneralTypeIssues]
), ),
) # type: ignore ) # type: ignore
@ -211,40 +201,13 @@ def app_with_1000_components(
yield AppHarness.create( yield AppHarness.create(
root=root, root=root,
app_source=functools.partial( app_source=functools.partial(
AppWithThousandComponentsOnePage, AppWithComponents,
render_component=render_component, # type: ignore render_component=render_component, # type: ignore
components=1000, # pyright: ignore [reportGeneralTypeIssues]
), ),
) # type: ignore ) # type: ignore
@pytest.mark.skipif(constants.IS_WINDOWS, reason=WINDOWS_SKIP_REASON)
@pytest.mark.benchmark(
group="Compile time of varying component numbers",
timer=time.perf_counter,
disable_gc=True,
warmup=False,
)
def test_app_10_compile_time_cold(benchmark, app_with_10_components):
"""Test the compile time on a cold start for an app with roughly 10 components.
Args:
benchmark: The benchmark fixture.
app_with_10_components: The app harness.
"""
def setup():
with chdir(app_with_10_components.app_path):
utils.empty_dir(web_pages, ["_app.js"])
app_with_10_components._initialize_app()
build.setup_frontend(app_with_10_components.app_path)
def benchmark_fn():
with chdir(app_with_10_components.app_path):
app_with_10_components.app_instance._compile()
benchmark.pedantic(benchmark_fn, setup=setup, rounds=10)
@pytest.mark.benchmark( @pytest.mark.benchmark(
group="Compile time of varying component numbers", group="Compile time of varying component numbers",
min_rounds=5, min_rounds=5,
@ -270,34 +233,6 @@ def test_app_10_compile_time_warm(benchmark, app_with_10_components):
benchmark(benchmark_fn) benchmark(benchmark_fn)
@pytest.mark.skipif(constants.IS_WINDOWS, reason=WINDOWS_SKIP_REASON)
@pytest.mark.benchmark(
group="Compile time of varying component numbers",
timer=time.perf_counter,
disable_gc=True,
warmup=False,
)
def test_app_100_compile_time_cold(benchmark, app_with_100_components):
"""Test the compile time on a cold start for an app with roughly 100 components.
Args:
benchmark: The benchmark fixture.
app_with_100_components: The app harness.
"""
def setup():
with chdir(app_with_100_components.app_path):
utils.empty_dir(web_pages, ["_app.js"])
app_with_100_components._initialize_app()
build.setup_frontend(app_with_100_components.app_path)
def benchmark_fn():
with chdir(app_with_100_components.app_path):
app_with_100_components.app_instance._compile()
benchmark.pedantic(benchmark_fn, setup=setup, rounds=5)
@pytest.mark.benchmark( @pytest.mark.benchmark(
group="Compile time of varying component numbers", group="Compile time of varying component numbers",
min_rounds=5, min_rounds=5,
@ -323,34 +258,6 @@ def test_app_100_compile_time_warm(benchmark, app_with_100_components):
benchmark(benchmark_fn) benchmark(benchmark_fn)
@pytest.mark.skipif(constants.IS_WINDOWS, reason=WINDOWS_SKIP_REASON)
@pytest.mark.benchmark(
group="Compile time of varying component numbers",
timer=time.perf_counter,
disable_gc=True,
warmup=False,
)
def test_app_1000_compile_time_cold(benchmark, app_with_1000_components):
"""Test the compile time on a cold start for an app with roughly 1000 components.
Args:
benchmark: The benchmark fixture.
app_with_1000_components: The app harness.
"""
def setup():
with chdir(app_with_1000_components.app_path):
utils.empty_dir(web_pages, keep_files=["_app.js"])
app_with_1000_components._initialize_app()
build.setup_frontend(app_with_1000_components.app_path)
def benchmark_fn():
with chdir(app_with_1000_components.app_path):
app_with_1000_components.app_instance._compile()
benchmark.pedantic(benchmark_fn, setup=setup, rounds=5)
@pytest.mark.benchmark( @pytest.mark.benchmark(
group="Compile time of varying component numbers", group="Compile time of varying component numbers",
min_rounds=5, min_rounds=5,